diff --git a/class.c b/class.c index a642ff0..9d346ee 100644 --- a/class.c +++ b/class.c @@ -927,7 +927,7 @@ static VALUE class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func) (st_data_t, st_data_t, st_data_t)) { VALUE ary; - int recur; + int recur, prepended = 0; st_table *list; if (argc == 0) { @@ -939,10 +939,15 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func recur = RTEST(r); } + if (!recur && RCLASS_ORIGIN(mod) != mod) { + mod = RCLASS_ORIGIN(mod); + prepended = 1; + } + list = st_init_numtable(); for (; mod; mod = RCLASS_SUPER(mod)) { if (RCLASS_M_TBL(mod)) st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)list); - if (BUILTIN_TYPE(mod) == T_ICLASS) continue; + if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue; if (obj && FL_TEST(mod, FL_SINGLETON)) continue; if (!recur) break; } diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index d7a6248..1a61535 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1299,4 +1299,9 @@ class TestModule < Test::Unit::TestCase end end end + + def test_prepend_instance_methods_fale + assert_equal([:m1], Class.new{ prepend Module.new; def m1; end }.instance_methods(false)) + assert_equal([:m1], Class.new(Class.new{def m2;end}){ prepend Module.new; def m1; end }.instance_methods(false)) + end end