module DescendantsTracker
Module that adds descendant tracking to a class
Constants
- VERSION
Unreleased gem version
Attributes
descendants[R]
Return the descendants of this class
@example
descendants = ParentClass.descendants
@return [Array<Class<DescendantsTracker>>]
@api public
Public Class Methods
setup(descendant)
click to toggle source
Setup the class for descendant tracking
@param [Class<DescendantsTracker>] descendant
@return [undefined]
@api private
# File lib/descendants_tracker.rb, line 24 def self.setup(descendant) descendant.instance_variable_set(:@descendants, ThreadSafe::Array.new) end
Also aliased as: extended
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 40 def add_descendant(descendant) ancestor = superclass if ancestor.respond_to?(:add_descendant) ancestor.add_descendant(descendant) end descendants.unshift(descendant) self end
Private Instance Methods
inherited(descendant)
click to toggle source
Hook called when class is inherited
@param [Class] descendant
@return [self]
@api private
Calls superclass method
# File lib/descendants_tracker.rb, line 58 def inherited(descendant) super DescendantsTracker.setup(descendant) add_descendant(descendant) end