Bugs: Browse | Submit New | Admin

[#4898] Subclasses of IO do not ensure that IO#close is called in block form

Date:
2006-06-30 15:18
Priority:
3
Submitted By:
Daniel Berger (djberg96)
Assigned To:
Akinori MUSHA (knu)
Category:
Files / Dirs / IO
State:
Open
Platform:
 
Summary:
Subclasses of IO do not ensure that IO#close is called in block form

Detailed description
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

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-05-25 15:28
Sender: Daniel Berger

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

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_tonone2007-06-12 01:22zenspider
category_idMisc / Other Standard Library2007-05-29 20:57zenspider
category_idLanguage / Runtime / Core Libraries2007-05-29 15:54zenspider