module Foo
  def shared
    'Foo shared'
  end
 
  def foobar
    shared
  end
end
 
module Moo
  def shared
    'Moo shared'
  end
 
  def moobar
    shared
  end
end
 
class Wingnut
  include Moo
  include Foo
end
 
w = Wingnut.new
 
w.foobar # => "Foo shared"
w.moobar # => "Foo shared"

2 Comments

  1. Jason Watkins

    Is this a surprise? Only if you think like Java rather than JavaScript. Self always points to the receiver, and method lookup is LIFO on the module chain.

  2. duncanbeevers

    Not surprising, just notable.

Leave a Comment

Enclose code in <code lang="ruby"></code> if you care.
Preview your comment using the button below.