Skip to content

Instantly share code, notes, and snippets.

@domgetter
Last active January 4, 2016 01:39
Show Gist options
  • Save domgetter/8549605 to your computer and use it in GitHub Desktop.
Save domgetter/8549605 to your computer and use it in GitHub Desktop.
# reads file backwards by byte
File.open("some_file.txt", "r") do |file|
file.size.downto(0) do |byte|
file.pos = byte
char = file.read(1)
puts char unless char =~ /\r/
end
end
9
8
7
6
5
4
3
2
8
7
6
5
4
3
2
1
=> 24
1234
5678
2345
6789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment