Class: Riml::Walker
- Inherits:
-
Object
- Object
- Riml::Walker
- Defined in:
- lib/walker.rb
Class Method Summary collapse
Class Method Details
.walk_node(node, method, walk_children = lambda {|n| true }) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/walker.rb', line 3 def self.walk_node(node, method, walk_children = lambda {|n| true }) # breadth-first walk to_visit = [node] while to_visit.length > 0 cur_node = to_visit.shift cur_node.children.each do |child| to_visit << child end if cur_node.respond_to?(:children) && walk_children.call(cur_node) method.call(cur_node) end end |