From: "David A. Black" Date: 2005-07-18T21:14:51+09:00 Subject: Re: Reading total lines of file then displaying in reverse? Hi -- On Mon, 18 Jul 2005, Tristan Knowles wrote: > > --- "David A. Black" wrote: >>> File.readlines("my.log").reverse.each{|l| puts l} >> >> I believe that's identical to: >> >> puts File.readlines("my.log").reverse > > > For my case, it now looks like this: > > lines = IO.readlines("my.log").reverse.each_with_index > do |line, index| > > > I'm trying to use .length somewhere now to count the > number of lines. One possibility: class Array def map_with_index res = [] each_with_index {|e,i| res << yield(e, i) } res end end puts File.readlines("my.log").map_with_index {|*a| a }.reverse (Not optimally efficient, I think, but anyway.) David -- David A. Black dblack@wobblini.net