lib/ostruct.rb: Revert "To use RuntimeError instead of FrozenError for old ruby versions."

This reverts commit 4cd1fc8b3559353069860eee90b1b5bade013917.
This commit is contained in:
Marc-Andre Lafortune 2020-09-02 15:34:33 -04:00
Родитель 3b0bcaf287
Коммит fbaab562d9
2 изменённых файлов: 4 добавлений и 6 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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