如何在 %w{} 中使用变量 [英] How to use variable inside %w{}

查看:48
本文介绍了如何在 %w{} 中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在现场使用变量 %w{} 但这仅生成字符串.

I want to use variable insite %w{} but this is generating only string.

我试过了

a="hello",
b="world"
%w{a b}

但这是显示 ["a", "b"] 我想显示 ["hello","world"]

But this is display ["a", "b"] I want to display ["hello","world"]

推荐答案

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

If you want to use variables you can use interpolation and the %W variant

a = "hello"
b = "world"

pp %W{#{a} #{b} this is normal text} #=> ["hello", "world", "this", "is", "normal", "text"]

这篇关于如何在 %w{} 中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆