Hi --

On Thu, 8 Jun 2006, Alder Green wrote:

> Hi
>
> I'm confused as to why class methods aren't include'd by default along
> with instance methods when mixing-in modules.
>
> It obstructs the important orthoganility between modules and classes,
> and - among other problems - thus undermines the position of mixins as
> an alternative to class-based multiple inheritance.
>
> In short, I can see a lot of poor consequence to that lack of support,
> while on the other hand no good reason for it. Maybe someone would
> care to elighten me?

It's actually a fairly specialized case.  In the general case, if a
module has a method of its own, there's no particular reason to think
that every class that mixes it in should also have that method.

For example:

   module Edible
     def self.definition
       "able to be eaten without ill effect"
     end
   end

   class Bread
     include Edible
   end

   class Bagel < Bread
   end

You don't really want Bread or Bagel reporting back their definitions
as being the same as Edible's definition.  You can arrange for that to
happen quite easily (see Phil's answer) if you want to, but you also
want to be able to have it not happen.

There's a huge amount of discussion of this in the mailing list
archives and on RCRchive.  People disagree, irreconcilably, and it's
not worth rehashing the whole thing.  But have a look at the archives
if you're interested.


David

-- 
David A. Black (dblack / wobblini.net)
* Ruby Power and Light, LLC (http://www.rubypowerandlight.com)
   > Ruby and Rails consultancy and training
* Author of "Ruby for Rails" from Manning Publications!
   > http://www.manning.com/black