Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::Node#breadth_first_search
breadth_first_search() { |node| ... }
lib/prism/node.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 228
def breadth_first_search(&block)
queue = [self] #: Array[Prism::node]
while (node = queue.shift)
return node if yield node
queue.concat(node.compact_child_nodes)
end
nil
end
Returns the first node that matches the given block when visited in a depth-first search. This is useful for finding a node that matches a particular condition.
Example
node.breadth_first_search { |node| node.node_id == node_id }