module DescendantsTracker

Module that adds descendant tracking to a class

Constants

VERSION

Public Instance Methods

add_descendant(descendant) click to toggle source

Add the descendant to this class and the superclass

@param [Class] descendant

@return [self]

@api private

# File lib/descendants_tracker.rb, line 20
def add_descendant(descendant)
  superclass = self.superclass
  superclass.add_descendant(descendant) if superclass.respond_to?(:add_descendant)
  descendants.unshift(descendant)
  self
end
descendants() click to toggle source

Return the descendants of this class

@return [Array<Class>]

@api private

# File lib/descendants_tracker.rb, line 9
def descendants
  @descendants ||= []
end

Private Instance Methods

inherited(descendant) click to toggle source

Hook called when class is inherited

@param [Class] descendant

@return [undefined]

@api private

Calls superclass method
# File lib/descendants_tracker.rb, line 36
def inherited(descendant)
  super
  add_descendant(descendant)
end