mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/ostruct.rb: Raise RuntimeError when modifying frozen instances
instead of TypeError. Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dc215dcd9f
commit
b9e18abe4a
2 changed files with 4 additions and 4 deletions
|
@ -152,7 +152,7 @@ class OpenStruct
|
||||||
begin
|
begin
|
||||||
@modifiable = true
|
@modifiable = true
|
||||||
rescue
|
rescue
|
||||||
raise TypeError, "can't modify frozen #{self.class}", caller(3)
|
raise RuntimeError, "can't modify frozen #{self.class}", caller(3)
|
||||||
end
|
end
|
||||||
@table
|
@table
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,14 +46,14 @@ class TC_OpenStruct < Test::Unit::TestCase
|
||||||
o = OpenStruct.new
|
o = OpenStruct.new
|
||||||
o.a = 'a'
|
o.a = 'a'
|
||||||
o.freeze
|
o.freeze
|
||||||
assert_raise(TypeError) {o.b = 'b'}
|
assert_raise(RuntimeError) {o.b = 'b'}
|
||||||
assert_not_respond_to(o, :b)
|
assert_not_respond_to(o, :b)
|
||||||
assert_raise(TypeError) {o.a = 'z'}
|
assert_raise(RuntimeError) {o.a = 'z'}
|
||||||
assert_equal('a', o.a)
|
assert_equal('a', o.a)
|
||||||
o = OpenStruct.new :a => 42
|
o = OpenStruct.new :a => 42
|
||||||
def o.frozen?; nil end
|
def o.frozen?; nil end
|
||||||
o.freeze
|
o.freeze
|
||||||
assert_raise(TypeError, '[ruby-core:22559]') {o.a = 1764}
|
assert_raise(RuntimeError, '[ruby-core:22559]') {o.a = 1764}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete_field
|
def test_delete_field
|
||||||
|
|
Loading…
Reference in a new issue