此问题已在此处有答案:
What does %w(array) mean?(8个回答)3天前关闭。我是Ruby的新手。有人能帮我理解下面的语句是做什么的吗?
%w(www us ca jp)
wgx48brx1#
这是一个字符串数组文字。引用文档:%w and %W:字符串数组文字你可以用%w(不可插值)或%W(可插值)编写字符串数组:
%w and %W
%w
%W
%w[foo bar baz] # => ["foo", "bar", "baz"] %w[1 % *] # => ["1", "%", "*"] # Use backslash to embed spaces in the strings. %w[foo\ bar baz\ bat] # => ["foo bar", "baz bat"] %w(#{1 + 1}) # => ["\#{1", "+", "1}"] %W(#{1 + 1}) # => ["2"]
1条答案
按热度按时间wgx48brx1#
这是一个字符串数组文字。
引用文档:
%w and %W
:字符串数组文字你可以用
%w
(不可插值)或%W
(可插值)编写字符串数组: