Sha256: 741e50d1003412aaab3c2223d09c961ff248a8f4ef468edb65d2ee32e279a549
Contents?: true
Size: 529 Bytes
Versions: 13
Compression:
Stored size: 529 Bytes
Contents
# frozen_string_literal: true module SyntaxTree # Provides an interface for searching for a pattern of nodes against a # subtree of an AST. class Search attr_reader :pattern def initialize(pattern) @pattern = pattern end def scan(root) return to_enum(__method__, root) unless block_given? queue = [root] until queue.empty? node = queue.shift next unless node yield node if pattern.call(node) queue += node.child_nodes end end end end
Version data entries
13 entries across 13 versions & 1 rubygems