123456789_123456789_123456789_123456789_123456789_

Class: Prism::NodeFind::LineProcFind

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Find
Instance Chain:
self, Find
Inherits: Prism::NodeFind::Find
Defined in: lib/prism/node_find.rb

Overview

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

Instance Method Summary

Find - Inherited

#parse_file

Parse the given file path, returning a ::Prism::ParseResult or nil.

Instance Method Details

#find(callable)

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

[ GitHub ]

  
# File 'lib/prism/node_find.rb', line 151

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