From: James Edward Gray II Date: 2005-04-27T04:07:47+09:00 Subject: Clearing StringIO I'm working with StringIO to write some test code and it is behaving strangely. Check out this example: irb(main):001:0> require "stringio" => true irb(main):002:0> fake_file = StringIO.new => # irb(main):003:0> fake_file.puts "This is a test." => nil irb(main):004:0> fake_file.string => "This is a test.\n" irb(main):005:0> fake_file.truncate(0) => 0 irb(main):006:0> fake_file.string => "" irb(main):007:0> fake_file.puts " <= Junk!" => nil irb(main):008:0> fake_file.string => "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000 <= Junk!\n" Is that a bug? Yuck. I hand my "fake_file" off to some code to play with, but keep a reference for my testing purposes. At times, I need to clear the accumulated output, but as you can see truncate() is giving me fits. Can anyone suggest how I might clear the StringIO object, without replacing it? Thanks. James Edward Gray II