From: Eric Wong Date: 2015-03-30T00:16:04+00:00 Subject: [ruby-core:68677] Re: [Ruby trunk - Bug #11015] [Open] IO.copy_stream does not advance Tempfile destination This happens because Tempfile is not an IO in MRI, and io.c calls #to_path on it. This means MRI reopens the file using a different handle. Using #to_io in this case avoids the extra open and writes to the existing handle: IO.copy_stream(StringIO.new('foo'), file.to_io) But yeah, I wish Tempfile were a subclass of IO in MRI, too... Keep in mind, blindly calling #to_io isn't a good idea, either, since some classes (gzip/zlib writer, SSL sockets, etc) only expose #to_io for IO.select and we never want to write directly to those file handles.