diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-24 04:42:28 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-24 04:42:28 +0000 |
commit | 5f48e7f3bc5b59b13bcbb5b3659a3c5f486565ef (patch) | |
tree | f842b52c2d3f54c2728f0363f178ed86770d1961 /test | |
parent | 6e8d72a196d6d8364cac0d3793a8dfdfe2581365 (diff) | |
download | ruby-5f48e7f3bc5b59b13bcbb5b3659a3c5f486565ef.tar.gz ruby-5f48e7f3bc5b59b13bcbb5b3659a3c5f486565ef.tar.xz ruby-5f48e7f3bc5b59b13bcbb5b3659a3c5f486565ef.zip |
* proc.c (mnew): generate method object that wraps method_missing,
when #respond_to_missing? is defined.
* test/ruby/test_object.rb (test_respond_to_missing): add test
suites for #respond_to_missing? changes.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_object.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index eff463f30..47e4a640d 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -304,6 +304,39 @@ class TestObject < Test::Unit::TestCase end end + def test_respond_to_missing + c = Class.new + c.class_eval do + def respond_to_missing?(id) + if id == :foobar + true + else + false + end + end + def method_missing(id,*args) + if id == :foobar + return [:foo, *args] + else + super + end + end + end + + foo = c.new + assert_equal([:foo], foo.foobar); + assert_equal([:foo, 1], foo.foobar(1)); + assert(foo.respond_to?(:foobar)) + assert_equal(false, foo.respond_to?(:foobarbaz)) + assert_raise(NoMethodError) do + foo.foobarbaz + end + + foobar = foo.method(:foobar) + assert_equal([:foo], foobar.call); + assert_equal([:foo, 1], foobar.call(1)); + end + def test_send_with_no_arguments assert_raise(ArgumentError) { 1.send } end |