ruby-changes:50153
From: marcandre <ko1@a...>
Date: Wed, 7 Feb 2018 08:52:34 +0900 (JST)
Subject: [ruby-changes:50153] marcandRe: r62271 (trunk): lib/ostruct.rb: Use `FrozenError` instead of `RuntimeError`.
marcandre 2018-02-07 08:52:30 +0900 (Wed, 07 Feb 2018) New Revision: 62271 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62271 Log: lib/ostruct.rb: Use `FrozenError` instead of `RuntimeError`. Patch by Yuuji Yaginuma. [Fixes GH-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`. Modified files: trunk/lib/ostruct.rb trunk/test/ostruct/test_ostruct.rb Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 62270) +++ lib/ostruct.rb (revision 62271) @@ -156,7 +156,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L156 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 Index: test/ostruct/test_ostruct.rb =================================================================== --- test/ostruct/test_ostruct.rb (revision 62270) +++ test/ostruct/test_ostruct.rb (revision 62271) @@ -66,15 +66,15 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L66 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/