Project

General

Profile

Feature #8026

Need Module#prepended_modules

Added by Marc-Andre Lafortune about 3 years ago. Updated about 2 years ago.

Status:
Feedback
Priority:
Normal
[ruby-core:53159]

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.

prepended.pdf (99.4 KB) Marc-Andre Lafortune, 08/31/2013 08:29 AM


Related issues

Related to Ruby trunk - Bug #8841: Module#included_modules and prepended modules Open 08/31/2013
Duplicated by Ruby trunk - Feature #11879: `Module#prepended_modules` Open

History

#1 [ruby-core:56216] Updated by Yukihiro Matsumoto almost 3 years ago

I am OK with the idea.

Matz.

#2 [ruby-core:56222] Updated by Akinori MUSHA almost 3 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

#3 [ruby-core:56899] Updated by Marc-Andre Lafortune over 2 years ago

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?

#4 [ruby-core:56917] Updated by Yukihiro Matsumoto over 2 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.

#5 [ruby-core:60283] Updated by Hiroshi SHIBATA about 2 years ago

  • Target version changed from 2.1.0 to current: 2.2.0

#6 Updated by Nobuyoshi Nakada 4 months ago

Also available in: Atom PDF