Bug #8298
closedModule include inconsistency
Description
It has been suggested that I report this as a violation of the object model:
module M ; end
module N ; end
class C ; include M ; end
module M ; include N ; end
c = C.new
c.extend M
d = class << c ; self ; end
d.ancestors
=>[N, C, M, Object, Kernel]
This has been this way for a while...
Updated by matz (Yukihiro Matsumoto) over 12 years ago
- Status changed from Open to Rejected
This is official restriction on module mix-in.
- modifications to modules after they are included would not be change existing relation, thus
Nwill not be included toC. -
#includedoes not add already included modules, thusMwill not be included toc.singleton_method(butNwill be). -
#ancestorson a singleton classes does not show the singleton class itself.
The last one might be considered as a bug. But we have no plan to fix others.
Matz.
Updated by Student (Nathan Zook) over 12 years ago
I think that perhaps I was too brief. My complaint is only that N precedes M (and C) in the ancestor list. The other matters are clear.
module M ; def foo ; M ; end ; end
module N ; def foo ; N ; end ; end
class C ; include M ; end
module M ; include N ; end
c = C.new
c.extend M
c.foo
=> N
class D ; include M ; end
D.new.foo
=> M
Updated by marcandre (Marc-Andre Lafortune) over 12 years ago
Student (Nathan Zook) wrote:
I think that perhaps I was too brief. My complaint is only that
NprecedesM(andC) in the ancestor list. The other matters are clear.
Indeed, it is a bit surprising. When including M, it manages to include N (because it's not in the ancestor list because of (1)) and then won't include M itself, because of (2).
For the record, (3) is already changed in trunk. I still hope to see (1) and (2) addressed one day.