我开始喜欢单词数组,但今天我面临挑战:
> 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","\"about","us\"","reports'"]
我怎么能有空格元素?
解决方法
您可以转义空格字符
a = %w[ faq contact about\ us legal bug\ reports ] a # => ["faq","about us","bug reports"]
但我仍然考虑使用“完整”数组文字.在这种情况下,它们不那么令人困惑.