jstern / foshay.citilink.com (Josh Stern) writes:


> So in the case of method name or instance name clashes, the earlier
> entries in this sequence take priority?

Both superclasses and included modules are added to a chain. The later 
they are added, the closer to the front they are. Their methods will
be found first.

> I'm wondering about a slightly more complex example - where Main has a
> super class that has its own modules.  How do name clashes
> resolve in that case?

  module M1
    def meth
      puts "M1"
    end
  end
      
  class Base
    include M1
  end

  Base.new.meth      #->  M1

  class Child < Base
  end

  Child.new.meth     #->  M1

  class Base
    def meth
      puts "Base"
    end
  end

  Child.new.meth     #->  Base

  module M2
    def meth
      puts "M2"
    end
  end

  class Child
    include M2
  end

  Child.new.meth     #->  M2

  class Child
    def meth
      puts "Child"
    end
  end

  Child.new.meth     #->  Child


It's a simple chain, with the modules included in a class chained
behind that class, and super classes behind those. No module appears
more than once in the list.


Regards


Dave