Module: Tree::InternalChildrenListImplementation
- Includes:
- InternalChildrenImplementation
- Defined in:
- lib/modular_tree/implementations.rb
Overview
Demonstrates a linked list implementation
Instance Attribute Summary collapse
-
#first_child ⇒ Object
Returns the value of attribute first_child.
-
#next_sibling ⇒ Object
Returns the value of attribute next_sibling.
Instance Method Summary collapse
Methods included from InternalChildrenImplementation
Methods included from Implementation
Methods included from NodeProperty
Methods included from BranchesProperty
#bare?, #branches, #each_branch
Methods included from ChildrenProperty
Methods included from InternalImplementation
Instance Attribute Details
#first_child ⇒ Object
Returns the value of attribute first_child.
136 137 138 |
# File 'lib/modular_tree/implementations.rb', line 136 def first_child @first_child end |
#next_sibling ⇒ Object
Returns the value of attribute next_sibling.
137 138 139 |
# File 'lib/modular_tree/implementations.rb', line 137 def next_sibling @next_sibling end |
Instance Method Details
#attach(child) ⇒ Object
152 153 154 155 |
# File 'lib/modular_tree/implementations.rb', line 152 def attach(child) child.instance_variable_set(:@next_sibling, first_child) @first_child = child end |
#children ⇒ Object
139 140 141 142 143 144 |
# File 'lib/modular_tree/implementations.rb', line 139 def children n = self.first_child or return [] a = [n] a << n while n = n.next_sibling a end |
#each_child {|curr| ... } ⇒ Object
146 147 148 149 150 |
# File 'lib/modular_tree/implementations.rb', line 146 def each_child(&block) curr = first_child or return yield(curr) yield curr while curr = next_sibling end |