Skip to content

Instantly share code, notes, and snippets.

@tsujigiri
Created July 31, 2011 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsujigiri/1117141 to your computer and use it in GitHub Desktop.
Save tsujigiri/1117141 to your computer and use it in GitHub Desktop.
Read a file line by line beginning at the last one
file = File.open("some_file.txt", "r")
pos = file.size
file.pos = pos
while pos >= 0
if file.readchar == "\n"
line = file.readline
# do something with line
end
pos -= 2
file.pos = pos
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment