Module: DescendantsTracker

Defined in:
lib/descendants_tracker.rb,
lib/descendants_tracker/version.rb

Overview

Module that adds descendant tracking to a class

Constant Summary collapse

VERSION =
'0.0.1'.freeze

Instance Method Summary collapse

Instance Method Details

#add_descendant(descendant) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add the descendant to this class and the superclass

Parameters:

  • descendant (Class)

Returns:

  • (self)


20
21
22
23
24
25
# 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

#descendantsArray<Class>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the descendants of this class

Returns:

  • (Array<Class>)


9
10
11
# File 'lib/descendants_tracker.rb', line 9

def descendants
  @descendants ||= []
end