Skip to content

Commit

Permalink
lib/ostruct.rb: Use FrozenError instead of RuntimeError.
Browse files Browse the repository at this point in the history
Patch by Yuuji Yaginuma. [Fixes rubyGH-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
  • Loading branch information
marcandre committed Feb 6, 2018
1 parent d3513d3 commit b16eaf8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ostruct.rb
Expand Up @@ -156,7 +156,7 @@ def modifiable? # :nodoc:
begin
@modifiable = true
rescue
raise RuntimeError, "can't modify frozen #{self.class}", caller(3)
raise FrozenError, "can't modify frozen #{self.class}", caller(3)
end
@table
end
Expand Down
6 changes: 3 additions & 3 deletions test/ostruct/test_ostruct.rb
Expand Up @@ -66,15 +66,15 @@ def test_frozen
o = OpenStruct.new(foo: 42)
o.a = 'a'
o.freeze
assert_raise(RuntimeError) {o.b = 'b'}
assert_raise(FrozenError) {o.b = '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(42, o.foo)
o = OpenStruct.new :a => 42
def o.frozen?; nil end
o.freeze
assert_raise(RuntimeError, '[ruby-core:22559]') {o.a = 1764}
assert_raise(FrozenError, '[ruby-core:22559]') {o.a = 1764}
end

def test_delete_field
Expand Down

0 comments on commit b16eaf8

Please sign in to comment.