下面的Ruby语句是什么意思?[副本]

a11xaf1n  于 2023-04-29  发布在  Ruby
关注(0)|答案(1)|浏览(160)

此问题已在此处有答案

What does %w(array) mean?(8个回答)
3天前关闭。
我是Ruby的新手。有人能帮我理解下面的语句是做什么的吗?

%w(www us ca jp)
wgx48brx

wgx48brx1#

这是一个字符串数组文字。
引用文档:
%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"]

相关问题