Reputation: 4164
Is there any way to combine more than one word together in %w(foo bar)
notation to get the resulting array as follows?
%w(foo bar foo or bar foo and bar) # => ["foo", "bar", "foo or bar", "foo and bar"]
Upvotes: 0
Views: 55
Reputation: 168111
Not using %w
notation, but with a similar spirit, using |
instead of space for a delimiter:
"foo|bar|foo or bar|foo and bar".split("|")
Upvotes: 0
Reputation: 15515
It's possible by using \
as the space character:
%w(foo bar foo\ or\ bar foo\ and\ bar) => ["foo", "bar", "foo or bar", "foo and bar"]
Upvotes: 1
Reputation: 106932
Yes, there is a way. You can excape a whitespace with \
:
%w(foo bar foo\ or\ bar foo\ and\ bar)
#=> ["foo", "bar", "foo or bar", "foo and bar"]
But I am not sure if this improves readability...
Upvotes: 2