Project

General

Profile

Actions

Feature #9779

open

Add Module#descendents

Added by shugo (Shugo Maeda) almost 10 years ago. Updated about 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:62193]

Description

Now classes have links to their subclasses, so how about to add Module#descendents?

class X
end

class Y < X
end

class Z < Y
end

p X.descendents    #=> [X, Y, Z]

module A
end

module B
  include A
end

module C
  include A
end

p A.descendents    #=> [A, C, B]

One of my own use cases is to implement AspectJ like pointcut which matches all subclasses of the given class.

Considerations:

  • Should the return value of Module#descendents include self?
  • Should the return value of Module#descendents include singleton classes?

I attach a patch, where the return value includes both self and singleton classes.


Files

0001-Add-Module-descendents.patch (3.75 KB) 0001-Add-Module-descendents.patch shugo (Shugo Maeda), 04/28/2014 07:00 AM

Related issues 1 (1 open0 closed)

Related to Ruby master - Feature #14394: Class.descendantsOpenko1 (Koichi Sasada)Actions

Updated by shugo (Shugo Maeda) almost 10 years ago

s/descendents/descendants/

Actions #2

Updated by naruse (Yui NARUSE) about 6 years ago

  • Target version deleted (2.2.0)
Actions #3

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0