Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created August 14, 2013 01:49
Show Gist options
  • Save domgetter/6227367 to your computer and use it in GitHub Desktop.
Save domgetter/6227367 to your computer and use it in GitHub Desktop.
file = File.new("testfile.txt", "r")
file.pos
=> 0
file.gets
=> "This is line one\n"
file.pos
=> 18
#This reports 18, but there are clearly 17 characters in that line.
# In fact, if you capture the gets to a variable, it reports its length correctly
file.rewind
=> 0
a = file.gets
=> "This is line one\n"
a.length
=> 17
file.pos
=> 18
# Is this expected behavior?
# I'm running ruby 2.0.0p247 (2013-06-27) [i386-mingw32]
# on Win7 64bit if that helps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment