Sha256: 905c3df344f88fffeb8d97cb7e814f5823834ccb013b213df6dffb16f4965aaa
Contents?: true
Size: 568 Bytes
Versions: 9
Compression:
Stored size: 568 Bytes
Contents
module Metamorpher module Rewriter class Traverser def traverse(tree) Enumerator.new(count(tree)) do |yielder| waiting = [tree] until waiting.empty? current = waiting.shift yielder << current waiting.concat(children(current)) end end end private def count(tree) children(tree).flat_map { |child| count(child) }.inject(1, :+) end def children(node) node.respond_to?(:children) ? node.children : [] end end end end
Version data entries
9 entries across 9 versions & 1 rubygems