我开始喜欢字阵,但今天我面临挑战:
> 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'"]
如何将空白作为元素?
答案 0 :(得分:15)
您可以转义空格字符
a = %w[ faq contact about\ us legal bug\ reports ]
a # => ["faq", "contact", "about us", "legal", "bug reports"]
但我仍然考虑使用“完整”数组文字。在这种情况下,它们不那么令人困惑。