如何在%w {}内使用变量

6 ruby

我想使用变量insite%w {}但这只生成字符串.

我试过了

a="hello",
b="world"
%w{a b}
Run Code Online (Sandbox Code Playgroud)

但这是显示 ["a", "b"]我要显示["你好","世界"]

Pau*_*l.s 15

如果要使用变量,可以使用插值和%W变量

a = "hello"
b = "world"

pp %W{#{a} #{b} this is normal text} #=> ["hello", "world", "this", "is", "normal", "text"]
Run Code Online (Sandbox Code Playgroud)