From: John Mair Date: 2010-10-07T10:59:16+09:00 Subject: Re: Why does Module#include exclude the module's metaclass? Thanks for your reply. But this argument seems too subtle for me. 1) I agree that singleton class of the module is actually a 'class' but (if we allowed this behavior) it would only be included when and only when the module is included. We can just consider this a special exception, no? This exception would only apply to singleton class of modules, of course, normal classes cannot be included in this way. 2) Given that class inheritance does include the singleton, do you not think it 'surprising' that module inclusion does not? I found it surprising. 3) Many people get around this limitation in module inclusion by abusing the included() hook and then extending a ClassMethods submodule, I think this is ugly. 3) Out of curiosity, are there any other reasons (besides the one you gave) for why modules do not include the singleton? What reason did Matz give? Thanks in advance, John Urabe Shyouhei wrote: > (2010/10/07 8:33), John Mair wrote: >> Ok, so my question: is there a theoretical/conceptual reason behind this >> limitation on modules? or was it just an implementation difficulty? > > The former. > > 1) So-called "class methods" are singleton methods of those Class class > instances. > > 2) A module's class methods are hence, singleton methods of a Module > class > instance. To say it in another word, they are instance methods of the > singleton class of such module. > > 3) So if you want a module inclusion to cause somewhat injecting a > module's > singleton methods into a class's, there should be this relationship: > > +---------+ +---------+ > | Meta A +---> Meta M | > +----^----+ +----^----+ > | | > +--+--+ +--+--+ > | A +-------> M | > +-----+ +-----+ > > 4) But this is impossible, because Meta M is a class. A class cannot be > included into another class. -- Posted via http://www.ruby-forum.com/.