File: countlines2.rb

Project: Invitation to Ruby

#!/usr/bin/env ruby

def filelines(file)
  count = 0
  while line = file.gets
    if line =~ /Ruby/
      count += 1
    end
  end
  count
end

if __FILE__ == $0 then
  puts "#{filelines($stdin)} lines"
end

Used by: countfilelines countfilelines2


[ Index ][ Table of Contents ]
Generated by [ source2html ]