# open the file File.open('foo.txt') do |file| # iterate over each line file.each_line do |line| puts line end end # since we passed a block, the file is automatically closed after `end`