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
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:)
Urabe S. wrote:
(2010/10/07 10:59), John M. wrote:
- 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
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
that. Your real_include gem breaks Class#ancestor in a strange way so I
there are some pitfalls, though noting particular.
- Given that class inheritance does include the singleton, do you not
think it ‘surprising’ that module inclusion does not? I found it
Tips: principle of least surprise is a wrong way for you to persuade
because at any moment he can say “I don’t think so”. Try a different
- 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
to smell like a API design mistake. I would recommend you to rethink
need such things.
- 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
No, I do not know other reasons. It is rather obvious to me. Of course
does not ensure there is not reason though.