Forum: Ruby-core [Open] Add Module#descendents

18a797893e6768e048c1d15429f96bb4?d=identicon&s=25 unknown (Guest)
on 2014-04-28 09:02
(Received via mailing list)
Issue #9779 has been reported by Shugo Maeda.

----------------------------------------
Feature #9779: Add Module#descendents
https://bugs.ruby-lang.org/issues/9779

* Author: Shugo Maeda
* Status: Open
* Priority: Normal
* Assignee:
* Category: core
* Target version: current: 2.2.0
----------------------------------------
Now classes have links to their subclasses, so how about to add
Module#descendents?

```ruby
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)
This topic is locked and can not be replied to.