?????????????????????????????飬????? rb_include_module ?????????????????????? rb_include_module ?????????????
void
rb_include_module(VALUE klass?? VALUE module)
{
int changed = 0;
rb_frozen_class_p(klass);
if (!OBJ_UNTRUSTED(klass)) {
rb_secure(4);
}
if (!RB_TYPE_P(module?? T_MODULE)) {
Check_Type(module?? T_MODULE);
}
OBJ_INFECT(klass?? module);
changed = include_modules_at(klass?? RCLASS_ORIGIN(klass)?? module);
if (changed < 0)
rb_raise(rb_eArgError?? "cyclic include detected");
if (changed) rb_clear_cache();
}
?????????rb_include_module ???????????????????????????????Щ?????????飬????????????????? include_modules_at ??????
static int
include_modules_at(const VALUE klass?? VALUE c?? VALUE module)
{
VALUE p;
int changed = 0;
const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
while (module) {
int superclass_seen = FALSE;
if (RCLASS_ORIGIN(module) != module)
goto skip;
if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
return -1;
/* ignore if the module included already in superclasses */
for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
switch (BUILTIN_TYPE(p)) {
case T_ICLASS:
if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
if (!superclass_seen) {
c = p;  /* move insertion point */
}
goto skip;
}
break;
case T_CLASS:
superclass_seen = TRUE;
break;
}
}
c = RCLASS_SUPER(c) = rb_include_class_new(module?? RCLASS_SUPER(c));
if (FL_TEST(klass?? RMODULE_IS_REFINEMENT)) {
VALUE refined_class =
rb_refinement_module_get_refined_class(klass);
st_foreach(RMODULE_M_TBL(module)?? add_refined_method_entry_i??
(st_data_t) refined_class);
FL_SET(c?? RMODULE_INCLUDED_INTO_REFINEMENT);
}
if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
changed = 1;
if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
changed = 1;
skip:
module = RCLASS_SUPER(module);
}
return changed;
}
????include_modules_at ?????????????????úú÷???????