From: Robert Klemme Date: 2011-01-26T20:51:33+09:00 Subject: Re: IO from text file On Wed, Jan 26, 2011 at 3:19 AM, Jeremy Bopp wrote: > On 01/25/2011 04:46 PM, Michael Litton wrote: >> I am trying to read in three strings from a .txt file. The code does >> everything but return the values stored in the file. >> >> Code: >> >> f = File.open('productlines.txt','r') >> >> lines = f.readlines >> >> lines.each do |line| >> >>   test = '#{line}' >           ^^^^^^^^^ > You need to use double quotes rather than single quotes here.  Single > quotes are meant to be used when you are likely to be defining string > contents that might otherwise be evaluated under double quotes. > Basically, you can more safely avoid escaping characters that have > special meaning.  In your case, you *want* to have the evaluation > performed, so you need the double quotes. :-) Note also that in this particular string evaluation is completely superfluous since the string around #{line} is empty, i.e. adds nothing. Basically this is sufficient lines.each do |line| line.chomp! # remove trailing nl puts "I read this line: #{line}." end You can as well do File.foreach do |line| line.chomp! # remove trailing nl puts "I read this line: #{line}." end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/