Ruby 中的字符串插值不起作用? [英] String interpolation in Ruby doesn't work?
本文介绍了Ruby 中的字符串插值不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近我从 Ruby 1.9.3 转向了 Ruby 2.0.0.
Recently I shifted to Ruby 2.0.0 from Ruby 1.9.3.
在 1.9.3 中,我们习惯于使用:'http://#{get_host_name}.com
来执行字符串插值,但是自从移动到 2.0.0,它似乎不起作用.
In 1.9.3 we were used to perform string interpolation using: 'http://#{get_host_name}.com
, but since moving to 2.0.0, it seems to be not working.
谁能告诉我语法是否改变了?如何在 Ruby 2.0.0 中执行字符串插值?
Can anyone tell me if the syntax changed? How can I perform string interpolation in Ruby 2.0.0?
推荐答案
无论您使用的是哪个版本的 Ruby,单引号字符串中都不会发生字符串插值.使用双引号字符串或 %Q
样式的字符串.
Regardless of which version of Ruby you're using, string interpolation doesn't happen in single-quoted strings. Use double-quoted strings or %Q
-style strings.
这篇关于Ruby 中的字符串插值不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文