Bug #7231
closedStringIO inconsistently raises IOError or RuntimeError if the string is frozen
Description
StringIO#ungetc, #ungetbyte raise RuntimeError if the data string is frozen. StringIO#write raises IOError.
Why?
1.9.3p286 :001 > require 'stringio'
=> true
1.9.3p286 :002 > s = StringIO.new x = "abc"
=> #StringIO:0x00000101020038
1.9.3p286 :003 > x.freeze
=> "abc"
1.9.3p286 :004 > s.ungetbyte 0x42
RuntimeError: can't modify frozen String
from (irb):4:in ungetbyte' from (irb):4 from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in
'
1.9.3p286 :005 > s.ungetc "w"
RuntimeError: can't modify frozen String
from (irb):5:in ungetc' from (irb):5 from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in
'
1.9.3p286 :006 > s.write "d"
IOError: not modifiable string
from (irb):6:in write' from (irb):6 from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in
'
Thanks,
Brian
Files