Feature #9112

Make module lookup more dynamic (Including modules into a module after it has already been included)

Added by Tobias Pfeiffer 5 months ago. Updated 5 months ago.

[ruby-core:58342]
Status:Assigned
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:core
Target version:-

Description

If a module (M) is included into a class (C) and afterwards another module (M2) is included into the first module (M) then C does not include M2 and instances do not respond to methods defined in M2. I think instances of C should respond to methods defined in M2 and C should include M2.

I created a gist detailing the problem I have: https://gist.github.com/PragTob/7472643

I think this behavior is confusing, because if I'd reopen module M and just add methods there then instances of C can call those methods. However if I include another module in M then instances of C can not call those methods.

Any opinions on if this would be a better behavior or why it isn't?

(was unsure to file it as a bug or feature)

History

#1 Updated by Eric Hodel 5 months ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto

This would be a new feature.

I believe this was requested and rejected back in the 1.8 days, but looking for the discussion is too difficult for me.

If it was, maybe matz has changed his mind

#2 Updated by Nobuyoshi Nakada 5 months ago

It has been rejected because it is hard to implement without significant performance penalty.
Now we have subclass trees, so it might be possible.

#3 Updated by Tobias Pfeiffer 5 months ago

Thank you for the quick reply Eric and Nobu! Looking forward to how this turns out :-)

#4 Updated by Hans Mackowiak 5 months ago

would it with the change also possible to add Module multible times into the Ancestor chain?
like
C1 < M1 < C2 < M1 < M2 < C3
?

#5 Updated by Nobuyoshi Nakada 5 months ago

Hanmac (Hans Mackowiak) wrote:

would it with the change also possible to add Module multible times into the Ancestor chain?

I'd tried it once, but found that some modules implicitly expect they are included only one time.
So, we'll need a way to tell a module can be included multiple times or not, perhaps.

Also available in: Atom PDF