From: Intransition Date: 2010-10-07T13:31:34+09:00 Subject: Re: Why does Module#include exclude the module's metaclass? On Oct 6, 7:33 pm, John Mair wrote: > When classes are inherited in Ruby the singleton classes are also > inherited: > > class A >   def self.hello >     puts "hello" >   end > end > > class B < A > end > > B.hello #=> "hello" > Yet with modules, this is not the case: > > module M >   def self.goodbye >     puts "goodbye" >   end > end > > class A >   include M > end > > A.goodbye #=> NameError > To get around this limitation many ppl resort to this ugly hack: > > module M >   def self.included(c) >     c.extend ClassMethods >   end > >   module ClassMethods >     def goodbye >       puts "goodbye" >     end >   end > end > Ok, so my question: is there a theoretical/conceptual reason behind this > limitation on modules? or was it just an implementation difficulty? > > After looking at the C source code (YARV/MRI) I can identify there is an > implementation difficulty (not insurmountable, but one all the same), > but is this the sole reason? Are there any other reasons for this > limitation? For no good reason other than a purely theoretical misconception concerning single vs multiple inheritance --at least that's the only reason I have ever been able to derive from my countless inquiries I've made into the subject. Over the years I have become increasing convinced that the distinction between class and module in Ruby is simply an artifice that inhibits the language unduly.