Class: Tgui::TreeView::TreeNode
- Defined in:
- lib/white_gold/dsl/tree_view.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #[](*path, grow: false) ⇒ Object
- #cut(*path, last) ⇒ Object
-
#initialize(object) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #path_str_to_object(path) ⇒ Object
Constructor Details
#initialize(object) ⇒ TreeNode
Returns a new instance of TreeNode.
24 25 26 27 |
# File 'lib/white_gold/dsl/tree_view.rb', line 24 def initialize object @object = object @nodes = {} end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
30 31 32 |
# File 'lib/white_gold/dsl/tree_view.rb', line 30 def nodes @nodes end |
#object ⇒ Object
Returns the value of attribute object.
29 30 31 |
# File 'lib/white_gold/dsl/tree_view.rb', line 29 def object @object end |
Instance Method Details
#[](*path, grow: false) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/white_gold/dsl/tree_view.rb', line 32 def [](*path, grow: false) if grow path.reduce(self){|node, str| node.nodes[str] ||= TreeNode.new nil } else path.reduce(self){|node, str| node&.nodes[str] } end end |
#cut(*path, last) ⇒ Object
40 41 42 |
# File 'lib/white_gold/dsl/tree_view.rb', line 40 def cut *path, last self[*path].nodes.delete last end |
#path_str_to_object(path) ⇒ Object
44 45 46 47 48 |
# File 'lib/white_gold/dsl/tree_view.rb', line 44 def path_str_to_object path objects = [] path.reduce(self){|node, str| node[str].tap{|n| objects << n.object } } objects end |