When you include
a module M
in a class C
, this is what happens:
- Ruby creates a class (let's call it
⟦M′⟧
) whose method table pointer, constant table pointer and class variable table pointer point to M
's method table, constant table and class variable table.
⟦M′⟧
's superclass pointer is set to C
's superclass.
C
's superclass pointer is set to ⟦M′⟧
.
If there are modules include
ed in M
, this process is applied recursively.
Note that the recursive flattening of mixins is applied once, when you call include
. Any changes in the inheritance hierarchy that are made afterwards will not be reflected.
However, when you add a method to M
's method table, that change will be reflected, because there is only one method table, to which both M
and ⟦M′⟧
refer.