From: tduehr@... Date: 2014-10-08T16:10:08+00:00 Subject: [ruby-core:65524] [ruby-trunk - Feature #9112] Make module lookup more dynamic (Including modules into a module after it has already been included) Issue #9112 has been updated by Timur Duehr. Thanks for the input. I think that's enough that I can start working on it. Porting the implementation I have for JRuby would yield O(N) method search time with recursion up to the deepest include/prepend. I'm pretty sure the current objects will not need modification. Worst case, `RClass_ext` will need an additional array/linked list. Handling `super` calls gets a bit trickier. Since the current call location will no longer be directly in line with `self`'s class, the next superclass up from a leaf node in the graph will need to be searched for. Fortunately, this implementation also reduces the number of `T_ICLASS` objects required since only one is needed every time an include is performed. This search can also take an iterative approach trading call stack for a list on the stack. There's a way to do away with that list by linking the leaf nodes (included modules) to the next/previous node in the search but that'll add complexity to `include`. My intent is to start with an iterative BFS since that should be a good tradeoff between complexity and size, and it shouldn't be too hard to extend to a threaded BFS search. Does that sound like a good approach? ---------------------------------------- Feature #9112: Make module lookup more dynamic (Including modules into a module after it has already been included) https://bugs.ruby-lang.org/issues/9112#change-49298 * Author: Tobias Pfeiffer * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto * Category: core * Target version: ---------------------------------------- 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) -- https://bugs.ruby-lang.org/