lib/compsci/node.rb in compsci-0.2.0.1 vs lib/compsci/node.rb in compsci-0.3.0.1
- old
+ new
@@ -48,15 +48,16 @@
end
end
# accumulate children; no child gaps
class FlexNode < Node
+ # These methods look like convenience methods, but they provide the
+ # FlexNode interface also used by ChildFlexNode
def add_child(node)
@children << node
end
- # TODO: are we passing everything needed to self.class.new ?
def new_child(value)
self.add_child self.class.new(value)
end
def add_parent(node)
@@ -93,9 +94,11 @@
@parent.set_child(idx, self)
end
end
# ChildNode which accumulates children with no gaps
+ # It meets the FlexNode API but does not inherit from FlexNode since it
+ # needs to reimplement each method; instead get parent stuff from ChildNode
class ChildFlexNode < ChildNode
def add_child(node)
node.parent ||= self
raise "node has a parent: #{node.parent}" if node.parent != self
@children << node