Ruby/File Directory/IO.readlines

Материал из Wiki.crossplatform.ru

Версия от 17:57, 13 сентября 2010; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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."



Read lines into an array

words = IO.readlines("/usr/share/dict/words")