Bugs item #4898, was opened at 2006-06-30 08:18
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=4898&group_id=426

Category: Core
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Daniel Berger (djberg96)
Assigned to: Nobody (None)
Summary: Subclasses of IO do not ensure that IO#close is called in block form

Initial Comment:
This bug was introduced in Ruby 1.8.3 and still exists as of the nightly snapshot as of 30-Jun-2006, so I didn't want it forgotten.

class Foo < IO
    def close
       STDOUT.puts "Hello"
       super
    end
end

if $0 == __FILE__
    Foo.open(File.open("testio.txt","w+").fileno){ |fh|
       fh.puts "hello"
    }
end

djberge@~/programming/ruby-514>ruby -v
ruby 1.8.2 (2004-12-25) [sparc-solaris2.10]
djberge@~/programming/ruby-515>ruby iotest.rb
Hello

djberge@~/programming/ruby-516>/opt/bin/ruby -v
ruby 1.8.5 (2006-06-29) [sparc-solaris2.10]
djberge@~/programming/ruby-517>/opt/bin/ruby iotest.rb

I originally reported this in ruby-core: 6911.

- Dan

----------------------------------------------------------------------

>Comment By: Daniel Berger (djberg96)
Date: 2007-05-25 08:28

Message:
On 1.8.6 I'm getting mixed results. Now the original code 
sample prints hello, but then it raises an error:

C:\Documents and Settings\djberge\workspace\ruby-foo>ruby 
iotest.rb
Hello
iotest.rb:10:in `write': not opened for writing (IOError)
        from iotest.rb:10:in `puts'
        from iotest.rb:10
        from iotest.rb:9:in `open'
        from iotest.rb:9

What's happening here?

Dan

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=4898&group_id=426