Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Ruby::Prism::Node#find
find(&blk)
lib/ruby/prism/node.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ruby/prism/node.rb, line 308
def breadth_first_search(&blk)
queue = [self] #: Array[node]
while (node = queue.shift)
return node if yield node
queue.concat(node.compact_child_nodes)
end
nil
end
Alias of #breadth_first_search
Returns the first node that matches the given block when visited in a breadth-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 }
: () { (node) -> bool } -> node?