Reading the file a line at a time:
count = File.foreach(filename).inject(0) {|c, line| c+1}
or the Perl-ish
File.foreach(filename) {}
count = $.
or
count = 0
File.open(filename) {|f| count = f.read.count("\n")}
Will be slower than
count = %x{wc -l #{filename}}.split.first.to_i