No commit activity in last 3 years
No release in over 3 years
Dynamically fetch subclasses and deep descendants!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.10
~> 10.0
>= 0
 Project Readme

descendants_fetcher

Build Status

This gem provides functionality similar to descendants_tracker but it doesn't store classes in the array. Instead of this it uses ObjectSpace approach to fetch descendant classes dynamically. It also separates descendants and subclasses: first is like ancestors but in opposite direction (deep), second matches strictly by superclass (children). See examples below.

The main cool feature of this implementation is that unlike with DescendantsTracker parent class doesn't store references to descendant class objects when inherited. It means that it can be safely used for dynamically created classes (via Class.new(...)).

The main caveat of this implementation is that it's obviously slower than DescendantsTracker.

Installation

Add this line to your application's Gemfile:

gem 'descendants_fetcher'

And then execute:

$ bundle

Or install it yourself as:

$ gem install descendants_fetcher

Usage

class X
  extend DescendantsFetcher
end

class X1 < X
end

class X2 < X
end

class Y < X1
end

X.descendants
# => [X, X1, X2, Y]

X.subclasses
# => [X1, X2]

X1.superclass
# => X

X2.superclass
# => X

Class.new(X) # This class object will be safely garbage-collected!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marshall-lee/descendants_fetcher.

License

The gem is available as open source under the terms of the MIT License.