Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/twitter_backup.rb
Instance Method Summary collapse
Instance Method Details
#tail(n) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/twitter_backup.rb', line 31 def tail(n) buffer = 1024 idx = (size - buffer).abs chunks = [] lines = 0 begin seek(idx) chunk = read(buffer) lines += chunk ? chunk.count("\n") : 0 chunks.unshift chunk idx -= buffer end while lines < ( n + 1 ) && pos != 0 tail_of_file = chunks.join('') ary = tail_of_file.split(/\n/) lines_to_return = ary[ ary.size - n, ary.size - 1 ] || [] end |