From 66a97945e30119503b43d0d2b8dde62c961c3c17 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 25 Sep 2009 04:04:48 +0000 Subject: * proc.c (mnew): fix for instance method of Module, BasicObject and subclass of a class which overrides respond_to_missing?. based on a patch from Nikolai Lugovoi in [ruby-core:25748]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ proc.c | 2 +- test/ruby/test_object.rb | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f0656f507..f0bd2e5fdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Sep 25 13:04:46 2009 Nobuyoshi Nakada + + * proc.c (mnew): fix for instance method of Module, BasicObjec + and subclass of a class which overrides respond_to_missing?. + based on a patch from Nikolai Lugovoi in + [ruby-core:25748]. + Fri Sep 25 11:56:50 2009 Nobuyoshi Nakada * vm_method.c (rb_mod_method_defined): should return true or false. diff --git a/proc.c b/proc.c index ac6689d77d..c6333b067b 100644 --- a/proc.c +++ b/proc.c @@ -912,7 +912,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) ID rmiss = rb_intern("respond_to_missing?"); VALUE sym = ID2SYM(id); - if (!rb_method_basic_definition_p(klass, rmiss)) { + if (obj != Qundef && !rb_method_basic_definition_p(klass, rmiss)) { if (RTEST(rb_funcall(obj, rmiss, 1, sym))) { return rb_proc_new(missing_wrap, rb_assoc_new(obj, sym)); } diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index 47e4a640d9..37317cfd47 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -305,8 +305,7 @@ class TestObject < Test::Unit::TestCase end def test_respond_to_missing - c = Class.new - c.class_eval do + c = Class.new do def respond_to_missing?(id) if id == :foobar true @@ -335,6 +334,18 @@ class TestObject < Test::Unit::TestCase foobar = foo.method(:foobar) assert_equal([:foo], foobar.call); assert_equal([:foo, 1], foobar.call(1)); + + c = Class.new(c) + assert_equal(false, c.method_defined?(:foobar)) + assert_raise(NameError, '[ruby-core:25748]') do + c.instance_method(:foobar) + end + + m = Module.new + assert_equal(false, m.method_defined?(:foobar)) + assert_raise(NameError, '[ruby-core:25748]') do + m.instance_method(:foobar) + end end def test_send_with_no_arguments -- cgit v1.2.3