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

Class Public methods

descendants(klass)

πŸ“ Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 104
        def descendants(klass)
          klass.descendants
        end
πŸ”Ž See on GitHub

subclasses(klass)

πŸ“ Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 100
        def subclasses(klass)
          klass.subclasses
        end
πŸ”Ž See on GitHub

Instance Public methods

descendants()

πŸ“ Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 109
      def descendants
        subclasses = DescendantsTracker.reject!(self.subclasses)
        subclasses.concat(subclasses.flat_map(&:descendants))
      end
πŸ”Ž See on GitHub

subclasses()

πŸ“ Source code
# File activesupport/lib/active_support/descendants_tracker.rb, line 175
      def subclasses
        DescendantsTracker.subclasses(self)
      end
πŸ”Ž See on GitHub