ruby - removing escape characters when parsing a string from file -
i'm trying read file string interpolates variables defined in code, , substitutes string value of variables.
the text file:
my name #{name}
the code:
file = file.open("tesst.txt", "r") arr = [] name = "cdj" file.each_line.with_index { |line, index| puts line } file.close
desired output:
my name cdj
actual output:
my name #{name}
when output line.inspect:
"my name \#{name}"
can me format string correctly reads #{name} variable instead of string inserted escape character?
file= 'tesst.txt' name = 'cdj' file.readlines(file).each |line| eval("puts \"#{line}\"") end
Comments
Post a Comment