From fd7f69362923958fe11f979ffa1134e0e026b9fa Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 22 Jul 2011 22:32:11 -0700 Subject: [PATCH 2/2] Fix handling of respond_to_missing? after r32621 This makes respond_to? call respond_to_missing? if it has been overridden and a string which is not already in the symbol table is passed in. However, if respond_to_missing? has been overridden, a symbol is always created. --- test/ruby/test_object.rb | 13 +++++++++++++ vm_method.c | 6 +++++- 2 files changed, 18 insertions(+), 1 deletions(-) diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index 2935885..c4f0f79 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -334,6 +334,19 @@ class TestObject < Test::Unit::TestCase assert_nothing_raised(bug2494) {[b].flatten} end + def test_respond_to_missing_string + c = Class.new do + def respond_to_missing?(id, priv) + !(id !~ /\Agadzoks\d+\z/) ^ priv + end + end + foo = c.new + assert_equal(false, foo.respond_to?("gadzooks16")) + assert_equal(true, foo.respond_to?("gadzooks17", true)) + assert_equal(true, foo.respond_to?("gadzoks16")) + assert_equal(false, foo.respond_to?("gadzoks17", true)) + end + def test_respond_to_missing c = Class.new do def respond_to_missing?(id, priv) diff --git a/vm_method.c b/vm_method.c index cea26cd..cb9f885 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1246,7 +1246,11 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj) rb_scan_args(argc, argv, "11", &mid, &priv); if (!(id = rb_check_id(mid))) - return Qfalse; + if (rb_method_basic_definition_p(CLASS_OF(obj), respond_to_missing)) { + return Qfalse; + } else { + return rb_funcall(obj, respond_to_missing, 2, ID2SYM(rb_to_id(mid)), RTEST(priv) ? Qtrue : Qfalse); + } if (basic_obj_respond_to(obj, id, !RTEST(priv))) return Qtrue; return Qfalse; -- 1.7.5