From: Joel VanderWerf Date: 2010-04-21T05:53:21+09:00 Subject: [ruby-core:29675] Re: "include X; include Y" vs "include X, Y" Caleb Clausen wrote: > On 4/20/10, Daniel Berger wrote: >> It seems that when including multiple modules with identical method >> names there are different results when using multiple includes versus >> a single include with multiple arguments. In the the former case we >> get a "last method definition wins" but in the latter it's "first >> method definition wins". >> >> Is this expected behavior? If so, where is it documented? >> >> module X >> def hello >> puts "hello" >> end >> end >> >> module Y >> def hello >> puts "greetings" >> end >> end >> >> class Foo >> include X >> include Y >> end >> >> class Bar >> include X, Y >> end >> >> Foo.new.hello # => greetings >> Bar.new.hello # => hello > > I have seen this before as well. I would expect "include X, Y" to mean > "include X", then "include Y". But instead it is equivalent to > "include Y" then "include X". What if you think of it this way: class Bar inhertance.insert X, Y # pseudo-ruby end IMHO, it's nice to read the inheritance chain from left to right, as with class inheritance (class A < B...). Nevertheless, the doc does not match the current behavior: --------------------------------------------------------- Module#include include(module, ...) => self ------------------------------------------------------------------------ Invokes Module.append_features on each parameter in turn. It's clear from the source and the example above that rb_mod_include() iterates in reverse, but that isn't what "in turn" suggests.