ruby-changes:31323
From: marcandre <ko1@a...>
Date: Thu, 24 Oct 2013 00:13:40 +0900 (JST)
Subject: [ruby-changes:31323] marcandRe: r43402 (trunk): * lib/ostruct.rb: Raise RuntimeError when modifying frozen instances
marcandre 2013-10-24 00:13:19 +0900 (Thu, 24 Oct 2013) New Revision: 43402 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43402 Log: * lib/ostruct.rb: Raise RuntimeError when modifying frozen instances instead of TypeError. Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. Modified files: trunk/lib/ostruct.rb trunk/test/ostruct/test_ostruct.rb Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 43401) +++ lib/ostruct.rb (revision 43402) @@ -152,7 +152,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L152 begin @modifiable = true rescue - raise TypeError, "can't modify frozen #{self.class}", caller(3) + raise RuntimeError, "can't modify frozen #{self.class}", caller(3) end @table end Index: test/ostruct/test_ostruct.rb =================================================================== --- test/ostruct/test_ostruct.rb (revision 43401) +++ test/ostruct/test_ostruct.rb (revision 43402) @@ -46,14 +46,14 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L46 o = OpenStruct.new o.a = 'a' o.freeze - assert_raise(TypeError) {o.b = 'b'} + assert_raise(RuntimeError) {o.b = 'b'} assert_not_respond_to(o, :b) - assert_raise(TypeError) {o.a = 'z'} + assert_raise(RuntimeError) {o.a = 'z'} assert_equal('a', o.a) o = OpenStruct.new :a => 42 def o.frozen?; nil end o.freeze - assert_raise(TypeError, '[ruby-core:22559]') {o.a = 1764} + assert_raise(RuntimeError, '[ruby-core:22559]') {o.a = 1764} end def test_delete_field -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/