Ruby/File Directory/each line

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

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

collect the lines together

text=""
line_count = 0
File.open("text.txt").each do |line|
  line_count += 1
  text << line
end
puts "#{line_count} lines"



Text file line counter

line_count = 0
File.open("text.txt").each { |line| line_count += 1 }
puts line_count