Sha256: 67a8f7c7516044ca84c799f9824515818add01887977733a37c38da08c3ad97c
Contents?: true
Size: 702 Bytes
Versions: 2
Compression:
Stored size: 702 Bytes
Contents
# -*- coding: utf-8 -*- module TreeVisitor # # Prints TreeNode names indenting according to depth # class PrintTreeNodeVisitor < TreeNodeVisitor 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
treevisitor-0.1.5 | lib/treevisitor/visitors/print_tree_node_visitor.rb |
treevisitor-0.1.4 | lib/treevisitor/visitors/print_tree_node_visitor.rb |