I’m referring to the %w operator/constructor/whatever you may call it, used like this:
%w{ foo bar baz }
=> ["foo", "bar", "baz"]
I have several questions about it:
- What is the proper name of that
%w“thing”? Operator? Literal? Constructor? - Does it matter whether I use
{}s instead of[]s? - Are there any other things like this (for example, one that gives you an array of symbols instead)?
- Can they be nested (one
%winside another%w, in order to create nested arrays)? - Where can I find documentation about it?
Unsure about the “official” documentation but this is pretty good : http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#The_.25_Notation
Whether you use {} [] () or <> does not matter except if your string contains this character e.g.:
The syntax is pretty complex so remembering every variant is not very useful, but it can come in handy when you are hacking quickly and want to avoid taking care of escape characters manually.