File.readlines : Read lines together « File Directory « Ruby






File.readlines



lines = File.readlines("text.txt")
line_count = lines.size
text = lines.join

puts "#{line_count} lines"

 








Related examples in the same category

1.Counting Characters
2.You can also read an entire file into an array, split by lines