For the record: the result of the code snippet posted by rumoku is “B2”.

Interesting. It’s easy to explain how of the result, but for the why you would have to ask Ruby developers. ;-)

Anyway, if you look at the source code for Module#include (rb_mod_include in eval.c), you’ll see that the arguments for include are processes backwards. So, “include B2, B1” is equivalent to “include B1; include B2”.

You can’t choose. M2 is before M1 in the ancestors list, so its implementation of foo will used. A solution is to either use different names for those methods or utilize composition instead of inheritance.