lib/ostruct.rb: Use FrozenError
instead of RuntimeError
.
Patch by Yuuji Yaginuma. [Fixes GH-1808] In other classes, `FrozenError` will be raised if change the frozen object. In order to match the behavior, I think that `FrozenError` should use in `OpenStruct`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d3513d313e
commit
b16eaf8632
@ -156,7 +156,7 @@ class OpenStruct
|
|||||||
begin
|
begin
|
||||||
@modifiable = true
|
@modifiable = true
|
||||||
rescue
|
rescue
|
||||||
raise RuntimeError, "can't modify frozen #{self.class}", caller(3)
|
raise FrozenError, "can't modify frozen #{self.class}", caller(3)
|
||||||
end
|
end
|
||||||
@table
|
@table
|
||||||
end
|
end
|
||||||
|
@ -66,15 +66,15 @@ class TC_OpenStruct < Test::Unit::TestCase
|
|||||||
o = OpenStruct.new(foo: 42)
|
o = OpenStruct.new(foo: 42)
|
||||||
o.a = 'a'
|
o.a = 'a'
|
||||||
o.freeze
|
o.freeze
|
||||||
assert_raise(RuntimeError) {o.b = 'b'}
|
assert_raise(FrozenError) {o.b = 'b'}
|
||||||
assert_not_respond_to(o, :b)
|
assert_not_respond_to(o, :b)
|
||||||
assert_raise(RuntimeError) {o.a = 'z'}
|
assert_raise(FrozenError) {o.a = 'z'}
|
||||||
assert_equal('a', o.a)
|
assert_equal('a', o.a)
|
||||||
assert_equal(42, o.foo)
|
assert_equal(42, o.foo)
|
||||||
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(RuntimeError, '[ruby-core:22559]') {o.a = 1764}
|
assert_raise(FrozenError, '[ruby-core:22559]') {o.a = 1764}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete_field
|
def test_delete_field
|
||||||
|
Loading…
x
Reference in New Issue
Block a user