Module: Tree::Utils::TreePathHandler
- Included in:
- TreeNode
- Defined in:
- lib/tree/utils/path_methods.rb
Overview
Provides utility methods for path extraction
Node Path collapse
-
#path_as_array ⇒ Array
Returns the node-names from this node to the root as an array.
-
#path_as_string(separator = '=>') ⇒ String
Returns the path of this node from the root as a string, with the node names separated using the specified separator.
Instance Method Details
#path_as_array ⇒ Array
Returns the node-names from this node to the root as an array. The first element is the root node name, and the last element is this node’s name.
node
64 65 66 |
# File 'lib/tree/utils/path_methods.rb', line 64 def path_as_array get_path_name_array.reverse end |
#path_as_string(separator = '=>') ⇒ String
Returns the path of this node from the root as a string, with the node names separated using the specified separator. The path is listed left to right from the root node.
55 56 57 |
# File 'lib/tree/utils/path_methods.rb', line 55 def path_as_string(separator = '=>') path_as_array.join(separator) end |