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

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Get/set the parent of this object. It’s not recommended to set this directly as it may break the ancestory chain.

Returns:

  • (Object)


17
18
19
# File 'lib/cura/attributes/has_ancestry.rb', line 17

def parent
  @parent
end

Instance Method Details

#ancestorsArray<Object>

Get the ancestors of this object.

Returns:

  • (Array<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.

Returns:

  • (Boolean)


22
23
24
# File 'lib/cura/attributes/has_ancestry.rb', line 22

def parent?
  !@parent.nil?
end