class TreeBranch::Node
Main class the outlines the basic operations and structure of a node in the tree.
Attributes
children[R]
data[R]
Public Class Methods
new(data)
click to toggle source
# File lib/tree_branch/node.rb, line 15 def initialize(data) @data = data @children = [] end
Public Instance Methods
==(other)
click to toggle source
# File lib/tree_branch/node.rb, line 34 def ==(other) eql?(other) end
add(*children_to_add)
click to toggle source
# File lib/tree_branch/node.rb, line 20 def add(*children_to_add) children_to_add.flatten.each do |child| raise ArgumentError, "Improper class: #{child.class.name}" unless child.is_a?(self.class) @children << child end self end
eql?(other)
click to toggle source
# File lib/tree_branch/node.rb, line 30 def eql?(other) data == other.data && children == other.children end
to_s()
click to toggle source
# File lib/tree_branch/node.rb, line 38 def to_s "[#{self.class.name}] Data: #{data}, Child Count: #{children.length}" end