зеркало из https://github.com/github/ruby.git
class.c: from the origin class
* class.c (rb_obj_singleton_methods): collect methods from the origin class. [ruby-core:53207] [Bug #8044] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
be909b5e95
Коммит
99126a4c88
|
@ -1,3 +1,8 @@
|
|||
Wed Mar 13 15:13:04 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* class.c (rb_obj_singleton_methods): collect methods from the origin
|
||||
class. [ruby-core:53207] [Bug #8044]
|
||||
|
||||
Wed Mar 13 14:51:26 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* vm_method.c (rb_export_method): directly override the flag of method
|
||||
|
|
13
class.c
13
class.c
|
@ -1228,8 +1228,8 @@ rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
|
|||
VALUE
|
||||
rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
|
||||
{
|
||||
VALUE recur, ary, klass;
|
||||
st_table *list;
|
||||
VALUE recur, ary, klass, origin;
|
||||
st_table *list, *mtbl;
|
||||
|
||||
if (argc == 0) {
|
||||
recur = Qtrue;
|
||||
|
@ -1238,16 +1238,17 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
|
|||
rb_scan_args(argc, argv, "01", &recur);
|
||||
}
|
||||
klass = CLASS_OF(obj);
|
||||
origin = RCLASS_ORIGIN(klass);
|
||||
list = st_init_numtable();
|
||||
if (klass && FL_TEST(klass, FL_SINGLETON)) {
|
||||
if (RCLASS_M_TBL(klass))
|
||||
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
|
||||
if ((mtbl = RCLASS_M_TBL(origin)) != 0)
|
||||
st_foreach(mtbl, method_entry_i, (st_data_t)list);
|
||||
klass = RCLASS_SUPER(klass);
|
||||
}
|
||||
if (RTEST(recur)) {
|
||||
while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
|
||||
if (RCLASS_M_TBL(klass))
|
||||
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
|
||||
if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0)
|
||||
st_foreach(mtbl, method_entry_i, (st_data_t)list);
|
||||
klass = RCLASS_SUPER(klass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,15 @@ class TestObject < Test::Unit::TestCase
|
|||
assert_equal([:foo2], (o2.public_methods(false) - o0.public_methods(false)).sort)
|
||||
end
|
||||
|
||||
def test_methods_prepend
|
||||
bug8044 = '[ruby-core:53207] [Bug #8044]'
|
||||
o = Object.new
|
||||
def o.foo; end
|
||||
assert_equal([:foo], o.methods(false))
|
||||
class << o; prepend Module.new; end
|
||||
assert_equal([:foo], o.methods(false), bug8044)
|
||||
end
|
||||
|
||||
def test_instance_variable_get
|
||||
o = Object.new
|
||||
o.instance_eval { @foo = :foo }
|
||||
|
|
Загрузка…
Ссылка в новой задаче