lib/tree_graph.rb in tree_graph-0.2.2 vs lib/tree_graph.rb in tree_graph-0.2.3
- old
+ new
@@ -12,10 +12,22 @@
def tree_graph_bottom_up_in_same_order
BottomUpInSameOrder.new(self).tree_graph
end
+ EMPTY_ARRAY = []
+
+ class ::Object
+ def label_for_tree_graph
+ to_s
+ end
+
+ def children_for_tree_graph
+ EMPTY_ARRAY
+ end
+ end
+
module Node
attr_accessor :is_last
attr_reader :raw_node, :parent
@@ -42,10 +54,10 @@
def levels
[level] + children_nodes.map(&:tree_graph)
end
def ancestors
- return [] unless parent
+ return EMPTY_ARRAY unless parent
parent.ancestors + [parent]
end
def indent
ancestors.map do |a|