红宝石.为什么arr =%w {'a','b','c'} =>["a","b","c") [英] Ruby. Why arr = %w{'a', 'b', 'c'} => ["'a',", "'b',", "'c'"]
本文介绍了红宝石.为什么arr =%w {'a','b','c'} =>["a","b","c")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自这个问题 Ruby中的indexOf ,
想知道为什么使用Ruby arr =%w {'a','b','c'}#=>['a',",'b',",'c'"]
Wondering why in Ruby
arr = %w{'a', 'b', 'c'} #=> ["'a',", "'b',", "'c'"]
推荐答案
%w {one two}
是 ["one","two"]
的快捷方式:%w {......
表示法将以空格分隔的元素用作数组的字符串.
%w{one two}
is a shortcut for ["one", "two"]
: the %w{...}
notation takes the space-separated elements as strings for the array.
这实际上是%w {......
背后的全部原因:编写不带引号或逗号的数组以分隔元素,从而允许使用引号和逗号而不转义它们.
This is actually the whole reason behind %w{...}
: writing arrays without quotes or commas to separate the elements, thus allowing the use of quotes and commas without escaping them.
这篇关于红宝石.为什么arr =%w {'a','b','c'} =>["a","b","c")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文