Feature #8026
closedNeed Module#prepended_modules
Description
We should have a way to get the list of prepended modules of a class or module.
module Mixin
end
module Outer
prepend Mixin
end
Mixin.prepended_modules #=> []
Outer.prepended_modules #=> [Mixin]
See also bug #8025.
Files
Updated by matz (Yukihiro Matsumoto) over 11 years ago
I am OK with the idea.
Matz.
Updated by knu (Akinori MUSHA) over 11 years ago
What about adding Module#prepend?(other) also, which could be implemented in ruby as follows?
module Module
def prepend?(other)
ancestors.find { |mod|
break false if mod == self
mod == other
}
end
end
Updated by marcandre (Marc-Andre Lafortune) about 11 years ago
- File prepended.pdf prepended.pdf added
Slide added. I'm also proposing an optional flag to search only the receiver and not the ancestors.
I didn't put in prepend?
but it should also be added. On the other hand, Array.prepend?(Enumerable)
should return false, no?
Updated by matz (Yukihiro Matsumoto) about 11 years ago
- Status changed from Open to Feedback
I basically accept the idea.
But according to the slide, the optional include_ancestors
is true, but it does mean cherry-picking prepended modules from ancestor list. I cannot think of any use case of this behavior.
Matz.
Updated by hsbt (Hiroshi SHIBATA) almost 11 years ago
- Target version changed from 2.1.0 to 2.2.0
Updated by nobu (Nobuyoshi Nakada) almost 9 years ago
- Has duplicate Feature #11879: `Module#prepended_modules` added
Updated by naruse (Yui NARUSE) almost 7 years ago
- Target version deleted (
2.2.0)
Updated by mame (Yusuke Endoh) almost 5 years ago
matz (Yukihiro Matsumoto) wrote:
But according to the slide, the optional
include_ancestors
is true, but it does mean cherry-picking prepended modules from ancestor list. I cannot think of any use case of this behavior.
I guess include_ancestors
here means "modules prepended by prepended modules":
module A; end
module B; prepend A; end
module C; prepend B; end
C.prepended_modules(true) #=> [A, B]
C.prepended_modules(false) #=> [B]
So, include_ancestors
is not a good name; should it be called include_descendants
?
@marcandre (Marc-Andre Lafortune) , am I right?
Updated by mame (Yusuke Endoh) almost 5 years ago
Now I'm unsure if the feature is worth adding. It was accepted six years ago, but not implemented yet. I've never heard any actual trouble due to the lack.
Updated by matz (Yukihiro Matsumoto) almost 5 years ago
I am still OK with the idea (but not for ancestors). prepended_modules
should list direct prepended modules for the receiver.
Matz.