I was trying to use the following code to read lines from a file. But when reading a file, the contents are all in one line:
line_num=0 File.open(\'xxx.txt\'
File.foreach(filename).with_index do |line, line_num| puts "#{line_num}: #{line}" end
This will execute the given block for each line in the file without slurping the entire file into memory. See: IO::foreach.