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)。 –