这个函数比较简单,除了类型安全检查,它只是 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 函数做了许多工作,值得好好分析一下。