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\'
It is because of the endlines in each lines. Use the chomp method in ruby to delete the endline '\n' or 'r' at the end.
line_num=0 File.open('xxx.txt').each do |line| print "#{line_num += 1} #{line.chomp}" end