ruby each_line reads line break too?
Yes, each_line
includes line breaks. But you can strip them easily using chomp
:
File.foreach('test1.rb') do |line|
send line.chomp
end
Another way is to map strip
onto each line as it is returned. To read a file line-by-line, stripping whitespace and do something with each line you can do the following:
File.open("path to file").readlines.map(&:strip).each do |line|
(do something with line)
end