Project

General

Profile

Actions

Bug #8298

closed

Module include inconsistency

Added by Student (Nathan Zook) almost 11 years ago. Updated almost 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
1.8, 1.9, 2.0
[ruby-core:54472]

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) almost 11 years ago

  • Status changed from Open to Rejected

This is official restriction on module mix-in.

  1. modifications to modules after they are included would not be change existing relation, thus N will not be included to C.
  2. #include does not add already included modules, thus M will not be included to c.singleton_method (but N will be).
  3. #ancestors on 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) almost 11 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) almost 11 years ago

Student (Nathan Zook) wrote:

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.

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0