From: John Mair Date: 2010-10-07T21:29:02+09:00 Subject: Re: Why does Module#include exclude the module's metaclass? @Urabe, sorry if my reply seemed rude or snarky, i did not mean it that way :) yeah #ancestors behave strange with real_include, I think this is due to the fact that normal T_ICLASS store the actual module in the klass pointer but real_include store a singleton class there, which #ancestors does not expect. I think the best approach (if real_include or something like it accepted as a patch) would be to store the actual module in a hidden __module__ instance variable on the ICLASS (just like __attached__ for singleton class) and #ancestors can look at this instead of klass pointer. I can see some other arguments for not bringing in module singleton methods with #include, one for example is that the hook methods included() and extended() will be accessible to the class too, which is ugly. I think there are OK arguments either way; but it's not such a serious issue really - to be honest i was just curious why it is that way :) Thanks for your time:) John Urabe Shyouhei wrote: > (2010/10/07 10:59), John Mair wrote: >> 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. > > So you were actually not asking why, but claiming this is wrong. Not > sure for > that. Your real_include gem breaks Class#ancestor in a strange way so I > guess > there are some pitfalls, though noting particular. > >> 2) Given that class inheritance does include the singleton, do you not >> think it 'surprising' that module inclusion does not? I found it >> surprising. > > Tips: principle of least surprise is a wrong way for you to persuade > matz > because at any moment he can say "I don't think so". Try a different > route. > >> 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. > > Maybe. But I think a module's having class method is itself ugly. It > tends > to smell like a API design mistake. I would recommend you to rethink > why you > need such things. > >> 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? > > No, I do not know other reasons. It is rather obvious to me. Of course > that > does not ensure there is not reason though. -- Posted via http://www.ruby-forum.com/.