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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -