我有这样一个类:
class Example
def printThisVar(printThing)
print 'this is the var: #{printThing}'
end
end
然而,被打印在打印该字符串"this is the var: #{printThing}"
不"this is the var: exampleText"
。
有没有什么办法解决这一问题?谢谢!
你有单引号,而不是要print
串绕双引号。
class Example
def print_this_var(print_thing)
print 'this is the var: #{print_thing}'
end
end
foo = Example.new
foo.print_this_var("example_text")
#=> this is the var: #{print_thing}
改变方法定义
print "this is the var: #{print_thing}"
产量
#=> this is the var: example_text
串插不单引号工作。