Method: FileUtils#tail
- Defined in:
- lib/standard/facets/fileutils/slice.rb
#tail(filename, lines) ⇒ Object (private)
In block form, yields the last number of lines
of file filename
. In non-block form, it returns the lines as an array.
Note that this method slurps the entire file, so I don’t recommend it for very large files. If you want an advanced form of tail
, I suggest using file-tail, by Florian Frank (available on the RAA):
# Returns last 3 lines of 'myfile'
FileUtils.tail("myfile",3)
And no tail -f.
50 51 52 |
# File 'lib/standard/facets/fileutils/slice.rb', line 50 def tail(filename,lines) #:yield IO.readlines(filename).reverse[0..lines-1].reverse end |