From: Alexander Schofield Date: 2001-10-28T12:04:29+09:00 Subject: [ruby-talk:23660] Re: How to get a String to interpolate itself? You could try: var = 99 str = 'line with var to interpolate: #{var}' a = eval("\"#{str}\"") puts a or simply: var = 99 str = 'line with var to interpolate: #{var}' eval "puts \"#{str}\"" hope this helps. Phil Tomson wrote: > > I'm trying to read lines from a file that might contain something like: > > Here is a line with a variable to interpolate: #{var} > > Now when I read it in like: > > var = 99 > File.foreach("junk.rbt") {|line| > puts line > } > > of course I get the same line in the file with the #{var} in it. > I'd like to get: > Here is a line with a variable to interpolate: 99 > > I suspect there must be a way to do this since using "" causes > interpolation, how can I get an existing String to interpolate itself? > > Phil