Ruby Obtenha linha de um arquivo
# open the file
File.open('foo.txt') do |file|
# iterate over each line with its index
file.each_line.with_index(1) do |line, number|
puts "#{number}: #{line}"
end
end
# since we passed a block, the file is automatically closed after `end`
Mateusz Drewniak