Ruby arrays: %w vs %W
有什么不同?
%w引用像单引号''
(没有可变内插,更少的转义序列),而%W引号像双引号""
。
irb(main):001:0> foo="hello"
=> "hello"
irb(main):002:0> %W(foo bar baz #{foo})
=> ["foo", "bar", "baz", "hello"]
irb(main):003:0> %w(foo bar baz #{foo})
=> ["foo", "bar", "baz", "#{foo}"]
我发现的%W和%w的应用程序:
greetings = %W(hi hello #{"how do you do"})
# => ["hi", "hello", "how do you do"]
%W performs normal double quote substitutions. %w does not.
链接地址: http://www.djcxy.com/p/59400.html上一篇: push()与$ array [] = ....哪个最快?
下一篇: Ruby数组:%w vs%W