module Tree::Node::InstanceMethods
Attributes
children[W]
parent[RW]
Public Instance Methods
add_child(object)
click to toggle source
# File lib/tree_node.rb, line 33 def add_child object object.parent = self children << object end
children()
click to toggle source
# File lib/tree_node.rb, line 29 def children @children ||= [] end
map(direction, collecting_object = [], &block)
click to toggle source
# File lib/tree_node.rb, line 14 def map(direction, collecting_object = [], &block) if direction == :down collecting_object << block.call(self) children.each { |child| child.map(direction, collecting_object, &block) } else parent.map(direction, collecting_object, &block) if parent collecting_object << block.call(self) end collecting_object end
root(&block)
click to toggle source
# File lib/tree_node.rb, line 25 def root(&block) parent.root(&block) rescue block.call(self) end