-
-
Save mvorotyn/40f300b3c4f878ac0560 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Tree | |
| attr_accessor :children, :node_name | |
| def initialize(node_name, strucutre={}) | |
| @node_name = node_name | |
| @children = [] | |
| strucutre.each_pair do |k,v| | |
| @children.push(Tree.new(k,v)) | |
| end | |
| end | |
| def visit_all(&block) | |
| visit &block | |
| children.each {|c| c.visit_all &block} | |
| end | |
| def visit(&block) | |
| block.call self | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment