Project

General

Profile

Bug #6660 » prepend_instance_methods_false.patch

nagachika (Tomoyuki Chikanaga), 06/28/2012 03:42 AM

View differences:

class.c
927 927
class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func) (st_data_t, st_data_t, st_data_t))
928 928
{
929 929
    VALUE ary;
930
    int recur;
930
    int recur, prepended = 0;
931 931
    st_table *list;
932 932

  
933 933
    if (argc == 0) {
......
939 939
	recur = RTEST(r);
940 940
    }
941 941

  
942
    if (!recur && RCLASS_ORIGIN(mod) != mod) {
943
	mod = RCLASS_ORIGIN(mod);
944
	prepended = 1;
945
    }
946

  
942 947
    list = st_init_numtable();
943 948
    for (; mod; mod = RCLASS_SUPER(mod)) {
944 949
	if (RCLASS_M_TBL(mod)) st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)list);
945
	if (BUILTIN_TYPE(mod) == T_ICLASS) continue;
950
	if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
946 951
	if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
947 952
	if (!recur) break;
948 953
    }
test/ruby/test_module.rb
1299 1299
      end
1300 1300
    end
1301 1301
  end
1302

  
1303
  def test_prepend_instance_methods_fale
1304
    assert_equal([:m1], Class.new{ prepend Module.new; def m1; end }.instance_methods(false))
1305
    assert_equal([:m1], Class.new(Class.new{def m2;end}){ prepend Module.new; def m1; end }.instance_methods(false))
1306
  end
1302 1307
end