Module: KType::Composite

Defined in:
lib/k_type/composite.rb

Overview

Composite Design Pattern: refactoring.guru/design-patterns/composite

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject (readonly)

Children allow downwards navigation plus access to sub-components



25
26
27
# File 'lib/k_type/composite.rb', line 25

def children
  @children
end

#parentObject (readonly)

Parent allows upwards navigation to components



22
23
24
# File 'lib/k_type/composite.rb', line 22

def parent
  @parent
end

Instance Method Details

#attach_parent(parent) ⇒ Object



27
28
29
# File 'lib/k_type/composite.rb', line 27

def attach_parent(parent)
  @parent = parent
end


31
32
33
# File 'lib/k_type/composite.rb', line 31

def navigate_parent
  parent.nil? ? self : parent
end

#root?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/k_type/composite.rb', line 35

def root?
  parent.nil?
end