M
Michael Litton
Info:
New to Ruby
Mac OSX with Ruby 1.8.7
Running from command line
Textmate editor
Question:
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}'
puts 'I read this line: ' + test +'.'
end
File contents:
pkplus
aminoplex
tuffturf
Output:
I read this line: #{line}.
I read this line: #{line}.
I read this line: #{line}.
I read this line: #{line}.
I read this line: #{line}.
Not sure if I am reading file correctly or why it return five times?
Thanks for your guidance.
Michael
New to Ruby
Mac OSX with Ruby 1.8.7
Running from command line
Textmate editor
Question:
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}'
puts 'I read this line: ' + test +'.'
end
File contents:
pkplus
aminoplex
tuffturf
Output:
I read this line: #{line}.
I read this line: #{line}.
I read this line: #{line}.
I read this line: #{line}.
I read this line: #{line}.
Not sure if I am reading file correctly or why it return five times?
Thanks for your guidance.
Michael