Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::Pattern#scan
scan(root) { |node| ... }
lib/prism/pattern.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/prism/pattern.rb, line 79
def scan(root)
return to_enum(__method__, root) unless block_given?
@compiled ||= compile
queue = [root]
while (node = queue.shift)
yield node if @compiled.call(node)
queue.concat(node.compact_child_nodes)
end
end
Scan the given node and all of its children for nodes that match the pattern. If a block is given, it will be called with each node that matches the pattern. If no block is given, an enumerator will be returned that will yield each node that matches the pattern.