Marius Butuc
Marius Butuc

Reputation: 18250

Word array with whitespace

I came to love word arrays, but today I face a challenge:

 > a = %w[ faq contact 'about us' legal 'bug reports' ]
 => ["faq", "contact", "'about", "us'", "legal", "'bug", "reports'"] 
 > a = %w[ faq contact "about us" legal 'bug reports' ]
 => ["faq", "contact", "\"about", "us\"", "legal", "'bug", "reports'"] 

How can I have whitespace an element?

Upvotes: 8

Views: 2243

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230346

You can escape space characters

a = %w[ faq contact about\ us legal bug\ reports ]
a # => ["faq", "contact", "about us", "legal", "bug reports"]

But I'd still consider using "full" array literals. They are less confusing in this case.

Upvotes: 16

Related Questions