Skip to content

Commit 4cd1fc8

Browse files
committed
To use RuntimeError instead of FrozenError for old ruby versions.
1 parent 50e1ffd commit 4cd1fc8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/ostruct.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def modifiable? # :nodoc:
156156
begin
157157
@modifiable = true
158158
rescue
159-
raise FrozenError, "can't modify frozen #{self.class}", caller(3)
159+
exception_class = defined?(FrozenError) ? FrozenError : RuntimeError
160+
raise exception_class, "can't modify frozen #{self.class}", caller(3)
160161
end
161162
@table
162163
end

test/ostruct/test_ostruct.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ def test_frozen
6666
o = OpenStruct.new(foo: 42)
6767
o.a = 'a'
6868
o.freeze
69-
assert_raise(FrozenError) {o.b = 'b'}
69+
expected_error = defined?(FrozenError) ? FrozenError : RuntimeError
70+
assert_raise(expected_error) {o.b = 'b'}
7071
assert_not_respond_to(o, :b)
71-
assert_raise(FrozenError) {o.a = 'z'}
72+
assert_raise(expected_error) {o.a = 'z'}
7273
assert_equal('a', o.a)
7374
assert_equal(42, o.foo)
7475
o = OpenStruct.new :a => 42
7576
def o.frozen?; nil end
7677
o.freeze
77-
assert_raise(FrozenError, '[ruby-core:22559]') {o.a = 1764}
78+
assert_raise(expected_error, '[ruby-core:22559]') {o.a = 1764}
7879
end
7980

8081
def test_delete_field

0 commit comments

Comments
 (0)