ruby-changes:31326
From: marcandre <ko1@a...>
Date: Thu, 24 Oct 2013 00:14:32 +0900 (JST)
Subject: [ruby-changes:31326] marcandRe: r43405 (trunk): * lib/ostruct.rb: raise NoMethodError with a #name and #args.
marcandre 2013-10-24 00:14:17 +0900 (Thu, 24 Oct 2013) New Revision: 43405 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43405 Log: * lib/ostruct.rb: raise NoMethodError with a #name and #args. Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. Modified files: trunk/ChangeLog trunk/lib/ostruct.rb trunk/test/ostruct/test_ostruct.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 43404) +++ ChangeLog (revision 43405) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 24 00:11:24 2013 Marc-Andre Lafortune <ruby-core@m...> + + * lib/ostruct.rb: raise NoMethodError with a #name and #args. + Raise RuntimeError when modifying frozen instances + instead of TypeError. + (OpenStruct#each_pair): Return an enumerator with size + (OpenStruct#delete): Use the converted argument. + Patches by Kenichi Kamiya. [Fixes GH-383] + + * test/ostruct/test_ostruct.rb: Added tests for above. + Thu Oct 24 00:10:22 2013 Marc-Andre Lafortune <ruby-core@m...> * array.c: Add Array#to_h [Feature #7292] Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 43404) +++ lib/ostruct.rb (revision 43405) @@ -184,7 +184,9 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L184 elsif len == 0 @table[mid] else - raise NoMethodError, "undefined method `#{mid}' for #{self}", caller(1) + err = NoMethodError.new "undefined method `#{mid}' for #{self}", mid, args + err.set_backtrace caller(1) + raise err end end Index: test/ostruct/test_ostruct.rb =================================================================== --- test/ostruct/test_ostruct.rb (revision 43404) +++ test/ostruct/test_ostruct.rb (revision 43405) @@ -125,4 +125,14 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L125 assert_equal true, os1.eql?(os1.dup) assert_equal os1.hash, os1.dup.hash end + + def test_method_missing + os = OpenStruct.new + e = assert_raise(NoMethodError) { os.foo true } + assert_equal :foo, e.name + assert_equal [true], e.args + assert_match /#{__callee__}/, e.backtrace[0] + e = assert_raise(ArgumentError) { os.send :foo=, true, true } + assert_match /#{__callee__}/, e.backtrace[0] + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/