Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Ruby::Prism::Node#tunnel
tunnel(line, column)
lib/ruby/prism/node.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ruby/prism/node.rb, line 282
def tunnel(line, column)
queue = [self] #: Array[node]
result = [] #: Array[node]
offset = source.byte_offset(line, column)
while (node = queue.shift)
result << node
node.each_child_node do |child_node|
if child_node.start_offset <= offset && offset < child_node.end_offset
queue << child_node
break
end
end
end
result
end
Returns a list of nodes that are descendants of this node that contain the given line and column. This is useful for locating a node that is selected based on the line and column of the source code.
Important to note is that the column given to this method should be in bytes, as opposed to characters or code units.