Skip to content

Instantly share code, notes, and snippets.

@gsamokovarov
Created July 2, 2013 13:33
Show Gist options
  • Save gsamokovarov/5909330 to your computer and use it in GitHub Desktop.
Save gsamokovarov/5909330 to your computer and use it in GitHub Desktop.
# If you truncate a StrinIO and don't rewind it, the next write will have
# leading zeroes.
require 'stringio'
s = StringIO.new
s.write 'foo'
p s.string # => "foo"
s.truncate 0
# s.rewind
s.write 'bar'
p s.string # => "\u0000\u0000\u0000bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment