diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-23 15:14:17 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-23 15:14:17 +0000 |
commit | f9a169fff2831c0350a157a589c1fa3dfe8840ea (patch) | |
tree | e3ddc5a6e428775fea053d6dc308f89ecf1f82de | |
parent | 5b5de3984e31b75643ad3ffc97c149436498c33d (diff) |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | lib/ostruct.rb | 4 | ||||
-rw-r--r-- | test/ostruct/test_ostruct.rb | 10 |
3 files changed, 24 insertions, 1 deletions
@@ -1,3 +1,14 @@ +Thu Oct 24 00:11:24 2013 Marc-Andre Lafortune <[email protected]> + + * 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 <[email protected]> * array.c: Add Array#to_h [Feature #7292] diff --git a/lib/ostruct.rb b/lib/ostruct.rb index d3aea636a1..f51eb7b5db 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -184,7 +184,9 @@ class OpenStruct 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 diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index a28abe5211..70335f44af 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -125,4 +125,14 @@ class TC_OpenStruct < Test::Unit::TestCase 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 |