From: Urabe Shyouhei Date: 2010-07-22T16:58:09+09:00 Subject: Re: finding last line in a file (2010/07/22 15:35), Robert Klemme wrote: > On 07/22/2010 07:10 AM, Urabe Shyouhei wrote: >> (2010/07/22 14:08), Urabe Shyouhei wrote: >>> Take a look at the doc for File.readline. >> >> Oops... typo. I meant readlines. With it you can do something like >> File.readlines(f).last > > This is as inefficient as using File.foreach because it will read the > whole file. I believe Ted was looking for a more efficient solution. Then how about: File.open(f).each_line.inject(nil){|x,y|y} Slower than my first answer though.