我有以下问题:
person = "John", building = "Big Tower"
我想使用Ruby的字符串插值来产生以下内容:
"My friend John owns the building Big Tower"
这是正确的答案:
puts "My friend #{person} owns the building #{building}"
??
如果您希望变量赋值是Ruby代码,那是错误的。它应该是
person = "John"; building = "Big Tower"
或者
person, building = "John", "Big Tower"
对于这个问题,是的,只是插值是Ruby的功能,而不是Rails的功能。请尊重普通的Ruby及其开发人员,不要将其与Rails混淆。Rails只是在Ruby之上构建的框架。Rails并不是Ruby的唯一用途。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句