mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix Kernel#singleton_method with Module#Prepend
* proc.c (rb_obj_singleton_method): search the method entry from the origin class, for fix prepended modules. [Bug #14658] From: Vasiliy Ermolovich <younash@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5bcb76ebbd
commit
c7770f90bd
2 changed files with 13 additions and 3 deletions
6
proc.c
6
proc.c
|
@ -1771,11 +1771,11 @@ VALUE
|
||||||
rb_obj_singleton_method(VALUE obj, VALUE vid)
|
rb_obj_singleton_method(VALUE obj, VALUE vid)
|
||||||
{
|
{
|
||||||
const rb_method_entry_t *me;
|
const rb_method_entry_t *me;
|
||||||
VALUE klass;
|
VALUE klass = RCLASS_ORIGIN(rb_singleton_class_get(obj));
|
||||||
ID id = rb_check_id(&vid);
|
ID id = rb_check_id(&vid);
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
if (!NIL_P(klass = rb_singleton_class_get(obj)) &&
|
if (!NIL_P(klass) &&
|
||||||
respond_to_missing_p(klass, obj, vid, FALSE)) {
|
respond_to_missing_p(klass, obj, vid, FALSE)) {
|
||||||
id = rb_intern_str(vid);
|
id = rb_intern_str(vid);
|
||||||
return mnew_missing(klass, obj, id, rb_cMethod);
|
return mnew_missing(klass, obj, id, rb_cMethod);
|
||||||
|
@ -1784,7 +1784,7 @@ rb_obj_singleton_method(VALUE obj, VALUE vid)
|
||||||
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
|
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
|
||||||
obj, vid);
|
obj, vid);
|
||||||
}
|
}
|
||||||
if (NIL_P(klass = rb_singleton_class_get(obj)) ||
|
if (NIL_P(klass) ||
|
||||||
UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) ||
|
UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) ||
|
||||||
UNDEFINED_REFINED_METHOD_P(me->def)) {
|
UNDEFINED_REFINED_METHOD_P(me->def)) {
|
||||||
vid = ID2SYM(id);
|
vid = ID2SYM(id);
|
||||||
|
|
|
@ -782,6 +782,16 @@ class TestMethod < Test::Unit::TestCase
|
||||||
assert_equal(:bar, m.call, feature8391)
|
assert_equal(:bar, m.call, feature8391)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_singleton_method_prepend
|
||||||
|
bug14658 = '[Bug #14658]'
|
||||||
|
c1 = Class.new
|
||||||
|
o = c1.new
|
||||||
|
def o.bar; :bar; end
|
||||||
|
class << o; prepend Module.new; end
|
||||||
|
m = assert_nothing_raised(NameError, bug14658) {o.singleton_method(:bar)}
|
||||||
|
assert_equal(:bar, m.call, bug14658)
|
||||||
|
end
|
||||||
|
|
||||||
Feature9783 = '[ruby-core:62212] [Feature #9783]'
|
Feature9783 = '[ruby-core:62212] [Feature #9783]'
|
||||||
|
|
||||||
def assert_curry_three_args(m)
|
def assert_curry_three_args(m)
|
||||||
|
|
Loading…
Add table
Reference in a new issue