Class: Prism::NodeFind::LineProcFind

Inherits:
Find
  • Object
show all
Defined in:
lib/prism/node_find.rb,
sig/generated/prism/node_find.rbs

Overview

Finds the AST node for a non-lambda Proc using best-effort line matching. Used on non-CRuby implementations.

Instance Method Summary collapse

Instance Method Details

#find(callable) ⇒ Node?

Find the node for the given proc by matching on line.

: (Proc callable) -> Node?

Parameters:

  • callable (Proc)

Returns:



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/prism/node_find.rb', line 181

def find(callable)
  return unless (source_location = callable.source_location)
  return unless (result = parse_file(source_location[0]))

  start_line = source_location[1]

  result.value.find do |node|
    case node
    when ForNode
      node.location.start_line == start_line
    when CallNode
      node.block.is_a?(BlockNode) && node.location.start_line == start_line
    else
      false
    end
  end
end