Skip to content

Commit

Permalink
StringIO#write will raise an IOError if string is frozen.
Browse files Browse the repository at this point in the history
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
require 'stringio'

s = ""
f = StringIO.new(s, "w")
s.freeze
assert_raise(IOError){ f.write("foo") }

puts :ok
}}}
  • Loading branch information
Watson1978 committed Apr 5, 2011
1 parent 76acad6 commit a92305e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/stringio.rb
Expand Up @@ -493,6 +493,7 @@ def write(str)
return 0 if str.empty?

raise(IOError, "not opened for writing") unless @writable
raise(IOError, "not modifiable string") if @string.frozen?

if @append || (pos >= string.length)
# add padding in case it's needed
Expand Down

0 comments on commit a92305e

Please sign in to comment.