module Cura::Attributes::HasAncestry
Allows an object to have a `parent` and `ancestors`.
Attributes
parent[RW]
Get/set the parent of this object. It's not recommended to set this directly as it may break the ancestory chain.
@return [Object]
Public Class Methods
new(attributes={})
click to toggle source
Calls superclass method
# File lib/cura/attributes/has_ancestry.rb, line 5 def initialize(attributes={}) @ancestors = [] super end
Public Instance Methods
ancestors()
click to toggle source
Get the ancestors of this object.
@return [Array<Object>]
# 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
parent?()
click to toggle source
Determine if this object has a parent.
@return [Boolean]
# File lib/cura/attributes/has_ancestry.rb, line 20 def parent? !@parent.nil? end