Class: Prism::NodeFind::LineLambdaFind

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 lambda 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 lambda by matching on line.

: (Proc callable) -> Node?

Parameters:

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/prism/node_find.rb', line 156

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 LambdaNode
      node.location.start_line == start_line
    when CallNode
      node.block.is_a?(BlockNode) && node.location.start_line == start_line
    else
      false
    end
  end
end