Skip to Content Skip to Search

Active Support Descendants Tracker

This module provides an internal implementation to track descendants which is faster than iterating through ObjectSpace.

However Ruby 3.1 provide a fast native +Class#subclasses+ method, so if you know your code won’t be executed on older rubies, including ActiveSupport::DescendantsTracker does not provide any benefit.

Methods
D
S

Class Public methods

descendants(klass)

# File activesupport/lib/active_support/descendants_tracker.rb, line 102
def descendants(klass)
  klass.descendants
end

subclasses(klass)

# File activesupport/lib/active_support/descendants_tracker.rb, line 98
def subclasses(klass)
  klass.subclasses
end

Instance Public methods

descendants()

# File activesupport/lib/active_support/descendants_tracker.rb, line 107
def descendants
  subclasses = DescendantsTracker.reject!(self.subclasses)
  subclasses.concat(subclasses.flat_map(&:descendants))
end