[英]ruby watir-webdriver using a variable in a hash
我正在尝试创建一个在中间具有可变项的哈希。 我似乎无法让变量仅被视为文字来理解。 变量是数组颜色中的元素
如
text1 = {:style => 'background-color: variable;'}
我以为这样可以。
text1 = {:style => 'background-color: #{variable};'}
以下作品,但它是一种绕法
text2 = ''
text2 << "background-color: " << variable << ";"
text1 = {:style => text2}
如果要使用#{}
将变量插入字符串中,则需要使用双引号而不是单引号。
variable = "green"
text1 = {:style => "background-color: #{variable};"} #Notice the double quotes
#=> {:style=>"background-color: green;"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.