Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Ruby::Prism::Node#breadth_first_search_all
breadth_first_search_all() { |node| ... }
lib/ruby/prism/node.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ruby/prism/node.rb, line 327
def breadth_first_search_all(&blk)
queue = [self] #: Array[Ruby::Prism::node]
results = [] #: Array[Ruby::Prism::node]
while (node = queue.shift)
results << node if yield node
queue.concat(node.compact_child_nodes)
end
results
end
Returns all of the nodes that match the given block when visited in a breadth-first search. This is useful for finding all nodes that match a particular condition.
Example
node.breadth_first_search_all { |node| node.is_a?(Ruby::Prism::CallNode) }
: () { (node) -> bool } -> Array[node]