????Ruby 2.0 ???????????? Module#prepend ?????????? API ????????????????????????????????? prepend_features ???????????????????????????????????????????????????????У????????????????????嵽?????????????????????????嵽???????????????????????????????á?
????????????????????????????????????????????????????????У??? C ???????? A ?? B???? D ????????? A ?? B??
module A
def foo; 'A' end
end
module B
def foo; 'B' end
end
class C
prepend A?? B   # Prepending is done by this line
def foo; 'C' end
end
class D
include A?? B
def foo; 'D' end
end
C.ancestors # => [A?? B?? C?? Object?? Kernel?? BasicObject]
D.ancestors # => [D?? A?? B?? Object?? Kernel?? BasicObject]
C.new.foo # => 'A'
D.new.foo # => 'D'
?????? 10 ?У??????? C ?????????? A ?? B?????? A ?? B ???? C ??????????????? 21 ?? 22 ???е?????У??????????????? C ?????????У?A ?? B λ?? C ???????? D ?????????У?A ?? B λ?? D ???
????????????? 24 ?У?C.new.foo ???????? 'A'???????? A ????? C??λ????????????棬???????????????? A ?е? foo ??????
????????????????????????????????????????????????????????????C.ancestors ?????????? C ???????????????????????ū??? prepend ????????????Щ??????????????????????????????????? prepend ???????? Module#prepend ??????????
static VALUE
rb_mod_prepend(int argc?? VALUE *argv?? VALUE module)
{
int i;
ID id_prepend_features?? id_prepended;
CONST_ID(id_prepend_features?? "prepend_features");
CONST_ID(id_prepended?? "prepended");
for (i = 0; i < argc; i++)
Check_Type(argv[i]?? T_MODULE);
while (argc--) {
rb_funcall(argv[argc]?? id_prepend_features?? 1?? module);
rb_funcall(argv[argc]?? id_prepended?? 1?? module);
}
return module;
}