<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On Oct 22, 2007, at 2:44 PM, Ramon Leon wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">Ruby's modules don't allow this level of control.<SPAN class="Apple-converted-space">  </SPAN>Given modules with</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">conflicting methods, you either get all from one or all from the other</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">depending on the order you include them.<SPAN class="Apple-converted-space">  </SPAN>That is my understanding anyway.</FONT></P> </BLOCKQUOTE></DIV><BR><DIV>Ramon is basically correct - the difference is in the way the conflicts are resolved. If a method is defined in more than one place, which one is used?</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Ruby's modules work by inserting the module into the superclass chain. The order that modules are included is the order they're inserted, so by including module later in the sequence you can override earlier modules the same way a subclass can override a superclass. For example, the following script prints "a A":</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>module Uppercase</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">        </SPAN>def alpha</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">                </SPAN>'A'</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">        </SPAN>end</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>module Lowercase</DIV><DIV>  def alpha</DIV><DIV>    'a'</DIV><DIV>  end</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>class Upperfirst</DIV><DIV>  include Uppercase</DIV><DIV>  include Lowercase</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>class Uppersecond</DIV><DIV>  include Lowercase</DIV><DIV>  include Uppercase</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>first = Upperfirst.new</DIV><DIV>second = Uppersecond.new</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>puts "#{first.alpha} #{second.alpha}"</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Traits, on the other hand works by adding the methods directly into the class's method dictionary. It can't rely on inheritance to resolve conflicts, so it provides ways of explicitly resolving conflicts, as Ramon explained.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Colin</DIV></BODY></HTML>