Sha256: a3b359b38105e7f9c8c97a6dfc40bdf7b7257006f718e4f61805ed35815dab4e
Contents?: true
Size: 707 Bytes
Versions: 1
Compression:
Stored size: 707 Bytes
Contents
# -*- coding: utf-8 -*- module TreeVisitor # # Prints TreeNode names indenting according to depth # class PrintTreeNodeVisitor < BasicTreeNodeVisitor def initialize @depth = 0 end def enter_tree_node( tree_node ) str = "" (0...@depth).step { str << " |-" } if @depth == 0 puts str + tree_node.name.to_s else puts str + tree_node.name.to_s end @depth += 1 end def exit_tree_node( tree_node ) @depth -= 1 end def visit_leaf_node( leaf_node ) str = "" (0...@depth-1).step { str << " |-" } str << " | " puts str + leaf_node.name.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
treevisitor-0.1.6 | lib/treevisitor/visitors/print_tree_node_visitor.rb |