mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3fbc65d47f
commit
298349d03b
3 changed files with 26 additions and 2 deletions
|
@ -1,4 +1,8 @@
|
||||||
Wed Jul 27 01:05:23 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jul 27 01:05:28 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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.
|
* 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]
|
based on the second patch by Jeremy Evans at [ruby-core:38447]
|
||||||
|
|
|
@ -334,6 +334,19 @@ class TestObject < Test::Unit::TestCase
|
||||||
assert_nothing_raised(bug2494) {[b].flatten}
|
assert_nothing_raised(bug2494) {[b].flatten}
|
||||||
end
|
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
|
def test_respond_to_missing
|
||||||
c = Class.new do
|
c = Class.new do
|
||||||
def respond_to_missing?(id, priv)
|
def respond_to_missing?(id, priv)
|
||||||
|
|
|
@ -1259,8 +1259,15 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj)
|
||||||
ID id;
|
ID id;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &mid, &priv);
|
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;
|
return Qfalse;
|
||||||
|
}
|
||||||
if (basic_obj_respond_to(obj, id, !RTEST(priv)))
|
if (basic_obj_respond_to(obj, id, !RTEST(priv)))
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue