Class: CherryTree::Tree
- Inherits:
-
Object
- Object
- CherryTree::Tree
- Defined in:
- lib/ursa/cherry-tree/tree.rb
Instance Attribute Summary collapse
-
#current_deep_level ⇒ Object
Returns the value of attribute current_deep_level.
-
#current_parent ⇒ Object
Returns the value of attribute current_parent.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize ⇒ Tree
constructor
A new instance of Tree.
- #make_node(data) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#current_deep_level ⇒ Object
Returns the value of attribute current_deep_level.
3 4 5 |
# File 'lib/ursa/cherry-tree/tree.rb', line 3 def current_deep_level @current_deep_level end |
#current_parent ⇒ Object
Returns the value of attribute current_parent.
3 4 5 |
# File 'lib/ursa/cherry-tree/tree.rb', line 3 def current_parent @current_parent end |
#root ⇒ Object
Returns the value of attribute root.
3 4 5 |
# File 'lib/ursa/cherry-tree/tree.rb', line 3 def root @root end |
Instance Method Details
#make_node(data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ursa/cherry-tree/tree.rb', line 15 def make_node(data) node = Node.new(data, current_parent, current_deep_level) if current_parent current_parent.children << node end if block_given? old_current_parent = self.current_parent self.current_deep_level += 1 self.current_parent = node yield self.current_parent = old_current_parent self.current_deep_level -= 1 end node end |