The each{} method of the file instance is used to get each line of the file content.
Let's view the syntax of this method.
File.each {|line| }
line: This represents each line of the file content. It is provided by the each{} method.
Each line of the file content is returned.
Let's view a code example below.
# get file or create new filef = File.new("test.txt")# print each linef.each {|line| puts "#{f.lineno}: #{line}"}
test.txt and write some text to it.each{} method and f.lineno to print each line number and each line of the file, respectively.