1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

proc.c: call respond_to_missing? with a symbol

[ruby-core:91683] [Bug #15640]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2019-03-06 11:16:34 +00:00
parent a679e98e64
commit 7fed9a2df5
2 changed files with 29 additions and 8 deletions

21
proc.c
View file

@ -1386,6 +1386,15 @@ mnew_missing(VALUE klass, VALUE obj, ID id, VALUE mclass)
return method;
}
static VALUE
mnew_missing_by_name(VALUE klass, VALUE obj, VALUE *name, int scope, VALUE mclass)
{
VALUE vid = rb_str_intern(*name);
*name = vid;
if (!respond_to_missing_p(klass, obj, vid, scope)) return Qfalse;
return mnew_missing(klass, obj, SYM2ID(vid), mclass);
}
static VALUE
mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass,
VALUE obj, ID id, VALUE mclass, int scope, int error)
@ -1690,10 +1699,8 @@ obj_method(VALUE obj, VALUE vid, int scope)
const VALUE mclass = rb_cMethod;
if (!id) {
if (respond_to_missing_p(klass, obj, vid, scope)) {
id = rb_intern_str(vid);
return mnew_missing(klass, obj, id, mclass);
}
VALUE m = mnew_missing_by_name(klass, obj, &vid, scope, mclass);
if (m) return m;
rb_method_name_error(klass, vid);
}
return mnew(klass, obj, id, mclass, scope);
@ -1795,10 +1802,8 @@ rb_obj_singleton_method(VALUE obj, VALUE vid)
obj, vid);
}
if (!id) {
if (respond_to_missing_p(klass, obj, vid, FALSE)) {
id = rb_intern_str(vid);
return mnew_missing(klass, obj, id, rb_cMethod);
}
VALUE m = mnew_missing_by_name(klass, obj, &vid, FALSE, rb_cMethod);
if (m) return m;
goto undef;
}
me = rb_method_entry_at(klass, id);

View file

@ -494,6 +494,22 @@ class TestMethod < Test::Unit::TestCase
assert_include mmethods, :meth, 'normal methods are public by default'
end
def test_respond_to_missing_argument
obj = Struct.new(:mid).new
def obj.respond_to_missing?(id, *)
self.mid = id
true
end
assert_kind_of(Method, obj.method("bug15640"))
assert_kind_of(Symbol, obj.mid)
assert_equal("bug15640", obj.mid.to_s)
arg = Struct.new(:to_str).new("bug15640_2")
assert_kind_of(Method, obj.method(arg))
assert_kind_of(Symbol, obj.mid)
assert_equal("bug15640_2", obj.mid.to_s)
end
define_method(:pm0) {||}
define_method(:pm1) {|a|}
define_method(:pm2) {|a, b|}