Class: RubyRich::Tree::Node
- Inherits:
-
Object
- Object
- RubyRich::Tree::Node
- Defined in:
- lib/ruby_rich/tree.rb
Overview
树节点类
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#data ⇒ Object
Returns the value of attribute data.
-
#expanded ⇒ Object
Returns the value of attribute expanded.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add(name, data: nil) ⇒ Object
- #add_child(child_node) ⇒ Object
- #has_children? ⇒ Boolean
-
#initialize(name, data: nil) ⇒ Node
constructor
A new instance of Node.
- #leaf? ⇒ Boolean
Constructor Details
#initialize(name, data: nil) ⇒ Node
Returns a new instance of Node.
39 40 41 42 43 44 |
# File 'lib/ruby_rich/tree.rb', line 39 def initialize(name, data: nil) @name = name @children = [] @data = data @expanded = true end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
37 38 39 |
# File 'lib/ruby_rich/tree.rb', line 37 def children @children end |
#data ⇒ Object
Returns the value of attribute data.
37 38 39 |
# File 'lib/ruby_rich/tree.rb', line 37 def data @data end |
#expanded ⇒ Object
Returns the value of attribute expanded.
37 38 39 |
# File 'lib/ruby_rich/tree.rb', line 37 def @expanded end |
#name ⇒ Object
Returns the value of attribute name.
37 38 39 |
# File 'lib/ruby_rich/tree.rb', line 37 def name @name end |
Instance Method Details
#add(name, data: nil) ⇒ Object
51 52 53 54 55 |
# File 'lib/ruby_rich/tree.rb', line 51 def add(name, data: nil) child = Node.new(name, data: data) add_child(child) child end |
#add_child(child_node) ⇒ Object
46 47 48 49 |
# File 'lib/ruby_rich/tree.rb', line 46 def add_child(child_node) @children << child_node child_node end |
#has_children? ⇒ Boolean
61 62 63 |
# File 'lib/ruby_rich/tree.rb', line 61 def has_children? !@children.empty? end |
#leaf? ⇒ Boolean
57 58 59 |
# File 'lib/ruby_rich/tree.rb', line 57 def leaf? @children.empty? end |