123456789_123456789_123456789_123456789_123456789_

Module: Prism::NodeFind

Do not use. This module is for internal use only.

Overview

Finds the ::Prism AST node corresponding to a given Method, UnboundMethod, Proc, or Thread::Backtrace::Location. On CRuby, uses node_id from the instruction sequence for an exact match. On other implementations, falls back to best-effort matching by source location line number.

This module is autoloaded so that programs that don’t use find don’t pay for its definition.

Class Method Summary

Class Method Details

.find(callable, rubyvm)

NodeFind::Find the node for the given callable or backtrace location.

[ GitHub ]

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

def self.find(callable, rubyvm)
  case callable
  when Proc
    if rubyvm
      RubyVMCallableFind.new.find(callable)
    elsif callable.lambda?
      LineLambdaFind.new.find(callable)
    else
      LineProcFind.new.find(callable)
    end
  when Method, UnboundMethod
    if rubyvm
      RubyVMCallableFind.new.find(callable)
    else
      LineMethodFind.new.find(callable)
    end
  when Thread::Backtrace::Location
    if rubyvm
      RubyVMBacktraceLocationFind.new.find(callable)
    else
      LineBacktraceLocationFind.new.find(callable)
    end
  else
    raise ArgumentError, "Expected a Method, UnboundMethod, Proc, or Thread::Backtrace::Location, got #{callable.class}"
  end
end