hal9000 / hypermetrics.com writes:

> For that matter, I am not sure how Ruby handles name clashes --
> i.e., names defined in more than one included module. I suppose
> you simply use the fully qualified name?

Whenever you include a module, Ruby effectively[1] inserts that module as 
a parent class of the thing that includes it. Each additional include
gets added in the same way, latest ones at the front. These methods
are placed in the chain after the object's own class, so they won't
override anything defined in the class itself.

When Ruby is searching for a method to execute, it looks back up the
class chain until it finds a match, and then executes the method. So,
last method in wins.

  module M1
    def meth
      puts "m1"
    end
  end

  module M2
    def meth
      puts "m2"
    end
  end

  class C
  end

  c = C.new
  puts defined? c.meth   #=> nil

  class C
    include M1
  end

  c.meth                #=> m1

  class C
    include M2
  end

  c.meth                #=> m2

  # there's no going back--a module is only ever included once
  class C
    include M1
  end

  c.meth                #=> m2



In general, when you're thinking about polymorphism in Ruby, you need
not be constrained by the concepts of predefining interfaces or
inheriting from hierarchies. It's a different way of working if you're 
used to C++ or Java, but it _does_ work.

Regards


Dave


Footnotes: 
[1]  Actually it inserts a proxy for the module.