coo*_*rgo 2 ruby watir-webdriver
我正在尝试创建在其中间具有可变性的哈希.我似乎无法将变量视为变量仅作为文字.变量是数组颜色中的元素,
例如
text1 = {:style => 'background-color: variable;'}
Run Code Online (Sandbox Code Playgroud)
我认为这会奏效.
text1 = {:style => 'background-color: #{variable};'}
Run Code Online (Sandbox Code Playgroud)
以下工作,但它是一个圆形的方法
text2 = ''
text2 << "background-color: " << variable << ";"
text1 = {:style => text2}
Run Code Online (Sandbox Code Playgroud)
如果要使用变量将变量插入到字符串中#{},则需要使用双引号而不是单引号.
variable = "green"
text1 = {:style => "background-color: #{variable};"} #Notice the double quotes
#=> {:style=>"background-color: green;"}
Run Code Online (Sandbox Code Playgroud)