Get the longest line : IO.readlines « File Directory « Ruby






Get the longest line


arr = IO.readlines("myfile")
lines = arr.size
puts "myfile has #{lines} lines in it."

longest = arr.collect {|x| x.length}.max
puts "The longest line in it has #{longest} characters."

 








Related examples in the same category

1.Read lines into an array