Module: KType::Composite
- Defined in:
- lib/k_type/composite.rb
Overview
Composite Design Pattern: refactoring.guru/design-patterns/composite
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Children allow downwards navigation plus access to sub-components.
-
#parent ⇒ Object
readonly
Parent allows upwards navigation to components.
Instance Method Summary collapse
Instance Attribute Details
#children ⇒ Object (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 |
#parent ⇒ Object (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 |
#navigate_parent ⇒ Object
31 32 33 |
# File 'lib/k_type/composite.rb', line 31 def navigate_parent parent.nil? ? self : parent end |
#root? ⇒ Boolean
35 36 37 |
# File 'lib/k_type/composite.rb', line 35 def root? parent.nil? end |