Module: BrowserOfBabel::Holotheca::Holarchy::ClassMethods Private
- Included in:
- BrowserOfBabel::Holotheca
- Defined in:
- lib/browser_of_babel/holotheca/holarchy.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class methods for manipulating hierarchy.
Instance Attribute Summary collapse
- #child_class ⇒ Class? readonly private
- #parent_class ⇒ Class? readonly private
Instance Method Summary collapse
-
#>>(other) ⇒ Class
private
Define holarchy relationship where
otheris a part ofself. -
#depth ⇒ Integer
private
Depth of this holotheca class in the holarchy, starting from 0.
-
#holarchy(holotheca) ⇒ Class
private
Convenience method to establish holarchy with current class as the root.
-
#root ⇒ Class
private
Get root holotheca class for the holarchy.
Instance Attribute Details
#child_class ⇒ 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.
13 14 15 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 13 def child_class @child_class end |
#parent_class ⇒ 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.
11 12 13 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 11 def parent_class @parent_class end |
Instance Method Details
#>>(other) ⇒ 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.
Define holarchy relationship where other is a part of self.
52 53 54 55 56 57 58 59 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 52 def >>(other) raise ArgumentError, "#{other} is not a Holarchy" unless other < Holarchy self.child_class = other other.parent_class = self other end |
#depth ⇒ Integer
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.
Depth of this holotheca class in the holarchy, starting from 0.
63 64 65 66 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 63 def depth parent_class = @parent_class parent_class ? parent_class.depth + 1 : 0 end |
#holarchy(holotheca) ⇒ 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.
It is not possible to reliably redefine the holarchy after the first call.
Convenience method to establish holarchy with current class as the root. Also redefines BrowserOfBabel::Holotheca::Holarchy#initialize to have only one optional parameter for identifier,
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 36 def holarchy(holotheca) class_eval { def initialize(identifier = nil) = super(nil, identifier) } # Due to how `.>>` works, parent and child classes can be messed up # on redefinition of a holarchy, do not even try. top = holotheca.root self >> top unless top == self self end |
#root ⇒ 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.
Get root holotheca class for the holarchy.
70 71 72 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 70 def root Enumerator.produce(self) { _1.parent_class }.find { _1.parent_class.nil? } end |