Call me a newbee/noob, it's my first time with OO, and with trees, and with Ruby. However, I thought I would be able to add a node to a previously created one as is done in the following snippet:
#!/usr/bin ruby
# simple_trial_tree.rb
require 'tree'
root_node = Tree::TreeNode.new("origin", "Push button")
root_node << Tree::TreeNode.new("assets", "assets")
root_node.print_tree
nicely prints this minimal tree:
* origin
+---> assets
But then, if I try to add in the same way a child to the node assets
, like so:
require 'tree'
root_node = Tree::TreeNode.new("origin", "Push button")
root_node << Tree::TreeNode.new("assets", "assets")
assets << Tree::TreeNode.new("assets_av", "av")
root_node.print_tree
I get simple_trial_tree.rb:17:in ``<main>': undefined local variable or method ``assets' 'for main:Object (NameError)
(with the double back-ticks to be read as single ones).
However, the following way does work:
require 'tree'
root_node = Tree::TreeNode.new("origin", "Push button")
assets = Tree::TreeNode.new("assets", "assets")
root_node.add(assets)
assets_av = Tree::TreeNode.new("assets_av", "av")
assets.add(assets_av)
root_node.print_tree
and gives:
* origin
+---+ assets
+---> assets_av
Now I'm a bit confused as in the manual of Rubytree a whole branch with nodes can be added in 'about' the way I tried it to do (I guess the problem lies in the 'about'). What am I doing wrong here?