Module: Cura::Attributes::HasAncestry
- Included in:
- HasRelativeCoordinates, Component::Base
- 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.
15 16 17 |
# File 'lib/cura/attributes/has_ancestry.rb', line 15 def parent @parent end |
Instance Method Details
#ancestors ⇒ Array<Object>
Get the ancestors of this object.
27 28 29 30 31 32 33 |
# File 'lib/cura/attributes/has_ancestry.rb', line 27 def ancestors if @parent.nil? [] else @parent.respond_to?(:ancestors) ? [@parent] + @parent.ancestors : [@parent] end end |
#initialize(attributes = {}) ⇒ Object
5 6 7 8 9 |
# File 'lib/cura/attributes/has_ancestry.rb', line 5 def initialize(attributes={}) @ancestors = [] super end |
#parent? ⇒ Boolean
Determine if this object has a parent.
20 21 22 |
# File 'lib/cura/attributes/has_ancestry.rb', line 20 def parent? !@parent.nil? end |