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 =
Unreleased gem version
'0.0.4'.freeze
Instance Attribute Summary collapse
-
#descendants ⇒ Array<Class<DescendantsTracker>>
readonly
Return the descendants of this class.
Class Method Summary collapse
-
.setup(descendant) ⇒ undefined
(also: extended)
private
Setup the class for descendant tracking.
Instance Method Summary collapse
-
#add_descendant(descendant) ⇒ self
private
Add the descendant to this class and the superclass.
Instance Attribute Details
#descendants ⇒ Array<Class<DescendantsTracker>> (readonly)
Return the descendants of this class
16 17 18 |
# File 'lib/descendants_tracker.rb', line 16 def descendants @descendants end |
Class Method Details
.setup(descendant) ⇒ undefined Also known as: extended
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.
Setup the class for descendant tracking
25 26 27 |
# File 'lib/descendants_tracker.rb', line 25 def self.setup(descendant) descendant.instance_variable_set(:@descendants, ThreadSafe::Array.new) end |
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
41 42 43 44 45 46 47 48 |
# File 'lib/descendants_tracker.rb', line 41 def add_descendant(descendant) ancestor = superclass if ancestor.respond_to?(:add_descendant) ancestor.add_descendant(descendant) end descendants.unshift(descendant) self end |