Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
来自这个问题indexOf in Ruby,
想知道为什么在 Ruby 中 arr = %w{'a', 'b', 'c'} #=> ["'a',", "'b',", "'c'"]
arr = %w{'a', 'b', 'c'} #=> ["'a',", "'b',", "'c'"]
%w初始化数组,用空格分隔括号(或其他符号)中的内容(如果需要空格,用 转义\)。
%w
\
%w{one two}是 的快捷方式["one", "two"]:%w{...}符号将空格分隔的元素作为数组的字符串。
%w{one two}
["one", "two"]
%w{...}
这实际上是背后的全部原因%w{...}:编写不带引号或逗号的数组来分隔元素,从而允许使用引号和逗号而不转义它们。