How to read a file from bottom to top in Ruby?

Posted by two2twelve on Stack Overflow See other posts from Stack Overflow or by two2twelve
Published on 2010-06-11T16:11:19Z Indexed on 2010/06/11 16:12 UTC
Read the original article Hit count: 135

Filed under:
|
|

I've been working on a log viewer for a Rails app and have found that I need to read around 200 lines of a log file from bottom to top instead of the default top to bottom.

Log files can get quite large, so I've already tried and ruled out the IO.readlines("log_file.log")[-200..-1] method.

Are there any other ways to go about reading a file backwards in Ruby without the need for a plugin or gem?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby