Project

General

Profile

Bug #11445

Updated by nobu (Nobuyoshi Nakada) almost 9 years ago

In Ruby 1.9.3 cloned `StringIO` StringIO instance has influence on close state of original instance: 

 ~~~ruby 
 require 'stringio' 

 sio1 = StringIO.new( 'abc' ) 
 sio2 = sio1.clone 

 sio2.read 
 sio1.pos    # => 3, expected 0 

 sio2.close 
 sio1.closed?    # => true, expected false 
 ~~~ 

 If `File` File is used instead of `StringIO`, StringIO, close state is not shared between instances (position is). 

 This behaviour has changed in Ruby 2.0.0 (cloned `StringIO` StringIO instance does not close original instance). 

 It matters what definition for `IO` IO clone is, whether to share attributes (e.g. `pos`) pos) and/or state (`closed?`) (closed?) but the later is acting differently in 1.9.3 for `StringIO` StringIO and `File`. File. 

Back