Module: Cura::Attributes::HasAncestry
- Included in:
- HasRelativeCoordinates
- Defined in:
- lib/cura/attributes/has_ancestry.rb
Overview
Allows an object to have a ‘parent` and `ancestors`.
Instance Attribute Summary collapse
-
#parent ⇒ Object
Get/set the parent of this object.
Instance Method Summary collapse
-
#ancestors ⇒ Array<Object>
Get the ancestors of this object.
- #initialize(attributes = {}) ⇒ Object
-
#parent? ⇒ Boolean
Determine if this object has a parent.
Instance Attribute Details
#parent ⇒ Object
Get/set the parent of this object. It’s not recommended to set this directly as it may break the ancestory chain.
17 18 19 |
# File 'lib/cura/attributes/has_ancestry.rb', line 17 def parent @parent end |
Instance Method Details
#ancestors ⇒ Array<Object>
Get the ancestors of this object.
29 30 31 32 33 34 35 |
# File 'lib/cura/attributes/has_ancestry.rb', line 29 def ancestors if @parent.nil? [] else @parent.respond_to?(:ancestors) ? [@parent] + @parent.ancestors : [@parent] end end |
#initialize(attributes = {}) ⇒ Object
7 8 9 10 11 |
# File 'lib/cura/attributes/has_ancestry.rb', line 7 def initialize(attributes={}) @ancestors = [] super end |
#parent? ⇒ Boolean
Determine if this object has a parent.
22 23 24 |
# File 'lib/cura/attributes/has_ancestry.rb', line 22 def parent? !@parent.nil? end |