class Pry::Method::WeirdMethodLocator - pry-0.10.1 Documentation

# class Pry::Method::WeirdMethodLocator

This class is responsible for locating the real `Pry::Method` object captured by a binding.

Given a `Binding` from inside a method and a ‘seed’ Pry::Method object, there are primarily two situations where the seed method doesn’t match the Binding:

1. The Pry::Method is from a subclass 2. The Pry::Method represents a method of the same name

while the original was renamed to something else. For 1. we search vertically up the inheritance chain, and for 2. we search laterally along the object’s method table.

When we locate the method that matches the Binding we wrap it in Pry::Method and return it, or return nil if we fail.

### Attributes

method[RW]
target[RW]

### Public Class Methods

new(method, target) click to toggle source

@param [Pry::Method] method The seed method. @param [Binding] target The Binding that captures the method

    we want to locate.

    # File lib/pry/method/weird_method_locator.rb, line 45
    def initialize(method, target)
      @method, @target = method, target
    end

normal_method?(method, b) click to toggle source

Whether the given method object matches the associated binding. If the method object does not match the binding, then it’s most likely not the method captured by the binding, and we must commence a search.

@param [Pry::Method] method @param [Binding] b @return [Boolean]

    # File lib/pry/method/weird_method_locator.rb, line 28
    def normal_method?(method, b)
      method && (method.source_file && method.source_range rescue false) &&
      File.expand_path(method.source_file) == File.expand_path(b.eval('__FILE__')) &&
      method.source_range.include?(b.eval('__LINE__'))
    end

weird_method?(method, b) click to toggle source

    # File lib/pry/method/weird_method_locator.rb, line 34
    def weird_method?(method, b)
      !normal_method?(method, b)
    end

### Public Instance Methods

get_method() click to toggle source

@return [Pry::Method, nil] The Pry::Method that matches the

    given binding.

    # File lib/pry/method/weird_method_locator.rb, line 51
    def get_method
      find_method_in_superclass || find_renamed_method
    end

lost_method?() click to toggle source

@return [Boolean] Whether the Pry::Method is unrecoverable

    This usually happens when the method captured by the Binding
    has been subsequently deleted.

    # File lib/pry/method/weird_method_locator.rb, line 58
    def lost_method?
      !!(get_method.nil? && renamed_method_source_location)
    end