Question about .chomp with regards to reading in lines for .txt files

ruby

#1

How would one read in a line(from lets say a .txt file) using File.open("file.txt").each..... but without taking in the whole line? Is there a .chomp method for files?


#2

Each line in the text file ends with a newline character ("\n" == LF). chomp removes that character.


#3

And where would I add my .chomp method to File.open("file.txt") ?


#4

Inside the .each do loop:

___.each do |line|
    print line.chomp
end

This isn't tested. Please provide a link to the exercise so we can see what is asked for and test the code. Thank you.


#5

Awesome thanks that's exactly what I needed!
I simply used it for
File.open("to_do_list.txt").each do |line|
my_list.addToList(line.chomp)
end

Cheers