mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
lib/ostruct.rb: Revert "To use RuntimeError instead of FrozenError for old ruby versions."
This reverts commit 4cd1fc8b3559353069860eee90b1b5bade013917.
This commit is contained in:
parent
3b0bcaf287
commit
fbaab562d9
2 changed files with 4 additions and 6 deletions
|
@ -170,8 +170,7 @@ class OpenStruct
|
||||||
begin
|
begin
|
||||||
@modifiable = true
|
@modifiable = true
|
||||||
rescue
|
rescue
|
||||||
exception_class = defined?(FrozenError) ? FrozenError : RuntimeError
|
raise FrozenError, "can't modify frozen #{self.class}", caller(3)
|
||||||
raise exception_class, "can't modify frozen #{self.class}", caller(3)
|
|
||||||
end
|
end
|
||||||
@table
|
@table
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,16 +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
|
||||||
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
|
assert_raise(FrozenError) {o.b = 'b'}
|
||||||
assert_raise(expected_error) {o.b = 'b'}
|
|
||||||
assert_not_respond_to(o, :b)
|
assert_not_respond_to(o, :b)
|
||||||
assert_raise(expected_error) {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(expected_error, '[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…
Add table
Add a link
Reference in a new issue