I am new to Ruby. Can someone help me understand what does following statement do?
%w(www us ca jp)
I am new to Ruby. Can someone help me understand what does following statement do?
%w(www us ca jp)
That is a String-Array Literal.
Quote from the docs:
%w and %W
: String-Array LiteralsYou can write an array of strings with
%w
(non-interpolable) or%W
(interpolable):%w[foo bar baz] # => ["foo", "bar", "baz"] %w[1 % *] # => ["1", "%", "*"] # Use backslash to embed spaces in the strings. %w[foo\ bar baz\ bat] # => ["foo bar", "baz bat"] %w(#{1 + 1}) # => ["\#{1", "+", "1}"] %W(#{1 + 1}) # => ["2"]