ruby-changes:20637
From: nobu <ko1@a...>
Date: Wed, 27 Jul 2011 01:05:40 +0900 (JST)
Subject: [ruby-changes:20637] nobu:r32685 (trunk): * vm_method.c (obj_respond_to): fix the respond_to_missing? override
nobu 2011-07-27 01:05:30 +0900 (Wed, 27 Jul 2011) New Revision: 32685 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32685 Log: * vm_method.c (obj_respond_to): fix the respond_to_missing? override case. based on the patch by Jeremy Evans at [ruby-core:38417]. [Feature #5072] Modified files: trunk/ChangeLog trunk/test/ruby/test_object.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 32684) +++ ChangeLog (revision 32685) @@ -1,5 +1,9 @@ -Wed Jul 27 01:05:23 2011 Nobuyoshi Nakada <nobu@r...> +Wed Jul 27 01:05:28 2011 Nobuyoshi Nakada <nobu@r...> + * vm_method.c (obj_respond_to): fix the respond_to_missing? override + case. based on the patch by Jeremy Evans at [ruby-core:38417]. + [Feature #5072] + * parse.y (rb_check_id): make the given name a symbol or a string. based on the second patch by Jeremy Evans at [ruby-core:38447] Index: vm_method.c =================================================================== --- vm_method.c (revision 32684) +++ vm_method.c (revision 32685) @@ -1259,8 +1259,15 @@ ID id; rb_scan_args(argc, argv, "11", &mid, &priv); - if (!(id = rb_check_id(&mid))) + if (!(id = rb_check_id(&mid))) { + if (!rb_method_basic_definition_p(CLASS_OF(obj), respond_to_missing)) { + VALUE args[2]; + args[0] = ID2SYM(rb_to_id(mid)); + args[1] = priv; + return rb_funcall2(obj, respond_to_missing, 2, args); + } return Qfalse; + } if (basic_obj_respond_to(obj, id, !RTEST(priv))) return Qtrue; return Qfalse; Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 32684) +++ test/ruby/test_object.rb (revision 32685) @@ -334,6 +334,19 @@ 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/