diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 09d81b8a5a..b49df2d2d6 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -170,8 +170,7 @@ class OpenStruct begin @modifiable = true rescue - exception_class = defined?(FrozenError) ? FrozenError : RuntimeError - raise exception_class, "can't modify frozen #{self.class}", caller(3) + raise FrozenError, "can't modify frozen #{self.class}", caller(3) end @table end diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index afe6affdc0..831598086d 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -66,16 +66,15 @@ class TC_OpenStruct < Test::Unit::TestCase o = OpenStruct.new(foo: 42) o.a = 'a' o.freeze - expected_error = defined?(FrozenError) ? FrozenError : RuntimeError - assert_raise(expected_error) {o.b = 'b'} + assert_raise(FrozenError) {o.b = '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(42, o.foo) o = OpenStruct.new :a => 42 def o.frozen?; nil end o.freeze - assert_raise(expected_error, '[ruby-core:22559]') {o.a = 1764} + assert_raise(FrozenError, '[ruby-core:22559]') {o.a = 1764} end def test_delete_field