Skip to content

Instantly share code, notes, and snippets.

@mvorotyn
Forked from cato/gist:886490
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save mvorotyn/40f300b3c4f878ac0560 to your computer and use it in GitHub Desktop.

Select an option

Save mvorotyn/40f300b3c4f878ac0560 to your computer and use it in GitHub Desktop.
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