Hi,
In my quest to learn Ruby a few months ago I never did learn what the code that looks like this is:
%w{bla bla2 bla3}
What are those? What letters are available for after the %? What do they do?
Thank you,
Mitch
| SitePoint Sponsor |



Hi,
In my quest to learn Ruby a few months ago I never did learn what the code that looks like this is:
%w{bla bla2 bla3}
What are those? What letters are available for after the %? What do they do?
Thank you,
Mitch





It's a Perl-style quick array. That's the way I think of them at least, there's probably a more accurate description.
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?



Do you know of a place where I can read more about them?Originally Posted by samsm





I'm not sure there's that much to know.Originally Posted by xmitchx
http://phrogz.net/ProgrammingRuby/in...rraysandhashes
hello_i_am_a_new_array = %w{space separated stuff in here}
%w{space separated stuff in here}.any_array_method_here
%w{space separated stuff in here}.include?('separated') => true
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
It's just a simple shortcut. Example:
It builds an array of strings.Code:$ irb irb(main):001:0> %w{one two three four} => ["one", "two", "three", "four"] irb(main):002:0>
There is also %r for regexps.





This is general quoting syntax. qQwrx are valid specifiers.
http://phrogz.net/ProgrammingRuby/la...delimitedinput



Got it! Great page, thanks a lot.Originally Posted by stereofrog
![]()
Bookmarks