Method: Pry::Method.lookup_method_via_binding

Defined in:
lib/pry/method.rb

.lookup_method_via_binding(obj, method_name, method_type, target = TOPLEVEL_BINDING) ⇒ Method, UnboundMethod

In order to support 2.0 Refinements we need to look up methods inside the relevant Binding.

Parameters:

  • obj (Object)

    The owner/receiver of the method.

  • method_name (Symbol)

    The name of the method.

  • method_type (Symbol)

    The type of method: :method or :instance_method

  • target (Binding) (defaults to: TOPLEVEL_BINDING)

    The binding where the method is looked up.

Returns:

  • (Method, UnboundMethod)

    The ‘refined’ method object.



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/pry/method.rb', line 114

def lookup_method_via_binding(
  obj, method_name, method_type, target = TOPLEVEL_BINDING
)
  Pry.current[:obj] = obj
  Pry.current[:name] = method_name
  receiver = obj.is_a?(Module) ? "Module" : "Kernel"
  target.eval(
    "::#{receiver}.instance_method(:#{method_type})" \
    ".bind(Pry.current[:obj]).call(Pry.current[:name])"
  )
ensure
  Pry.current[:obj] = Pry.current[:name] = nil
end