Ruby does not have and does not require pointers, since most things are simply passed by reference.
> a = "hello" > b = a > a.object_id == b.object_id => true
In its simplest form, a node tree can be just a structure, with a parent and left and right siblings:
> Node = Struct.new(:parent, :left, :right) > root = Node.new > n1 = Node.new(root, "hello", "world") > root.left = n1 ... > root.left.left => "hello" > root.left.right => "world"
For more complete implementations, you can see, for example:
RubyTree:
http://rubytree.rubyforge.org/rdoc/
SimpleTree:
https://github.com/ealdent/simple-tree/blob/master/lib/simple_tree.rb
Casper
source share