0
我可以读取包含#{var_name}
的文件吗?当我读取并打印它时,请写入var_name
的值?在文本文件中读取带有变量的文件
我尝试使用
File.open(filename, "w").read
把它作为一个字符串,但我没有找到解决办法:
var_name = "HelloWorld"
f = File.open("file.ex", "r").read
# puts f.class => String
puts f
# #{var_name} is print and no HelloWorld
对此,您可以使用[ERB](http://ruby-doc.org/stdlib-2.2.3/libdoc/erb/rdoc/ERB.html)。 –