Class: CompSci::ChildNode
Overview
like Node but with a reference to its parent
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes inherited from Node
Instance Method Summary collapse
- #add_child(node) ⇒ Object
- #add_parent(node) ⇒ Object
-
#initialize(value) ⇒ ChildNode
constructor
A new instance of ChildNode.
Methods inherited from Node
Constructor Details
#initialize(value) ⇒ ChildNode
Returns a new instance of ChildNode.
43 44 45 46 |
# File 'lib/compsci/tree.rb', line 43 def initialize(value) @parent = nil super(value) end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
41 42 43 |
# File 'lib/compsci/tree.rb', line 41 def parent @parent end |
Instance Method Details
#add_child(node) ⇒ Object
48 49 50 51 52 |
# File 'lib/compsci/tree.rb', line 48 def add_child(node) node.parent ||= self raise "node has a parent: #{node.parent}" if node.parent != self super(node) end |
#add_parent(node) ⇒ Object
54 55 56 57 |
# File 'lib/compsci/tree.rb', line 54 def add_parent(node) @parent = node super(node) end |