Why doesn't this simple Ruby program print what I expect it to?

Posted by Michael Braxton on Stack Overflow See other posts from Stack Overflow or by Michael Braxton
Published on 2010-05-27T21:29:03Z Indexed on 2010/05/27 21:31 UTC
Read the original article Hit count: 138

Filed under:
|

I have this:

require 'tempfile'
t = Tempfile.new('test-data')
t.open
t.sync = true
t << "apples"
t.puts "bananas"
puts "contents are [#{t.read}] (#{t.size} bytes)"
t.close

This prints:

contents are [] (14 bytes)

Why aren't the contents actually shown? I'm on Ruby 1.9.2.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about temporary-files