Class Pry::Method
In: lib/pry/method.rb
Parent: Object

This class wraps the normal `Method` and `UnboundMethod` classes to provide extra functionality useful to Pry.

Methods

Included Modules

RbxMethod Helpers::DocumentationHelpers

Classes and Modules

Class Pry::Method::Disowned

External Aliases

from_class -> from_module

Public Class methods

Get all of the instance methods of a `Class` or `Module` @param [Class,Module] klass @param [Boolean] include_super Whether to include methods from ancestors. @return [Array[Pry::Method]]

Get all of the methods on an `Object` @param [Object] obj @param [Boolean] include_super Whether to include methods from ancestors. @return [Array[Pry::Method]]

Given a `Binding`, try to extract the `::Method` it originated from and use it to instantiate a `Pry::Method`. Return `nil` if this isn‘t possible.

@param [Binding] b @return [Pry::Method, nil]

Given a `Class` or `Module` and the name of a method, try to instantiate a `Pry::Method` containing the instance method of that name. Return `nil` if no such method exists.

@param [Class, Module] klass @param [String] name @return [Pry::Method, nil]

Given an object and the name of a method, try to instantiate a `Pry::Method` containing the method of that name bound to that object. Return `nil` if no such method exists.

@param [Object] obj @param [String] name @return [Pry::Method, nil]

Given a string representing a method name and optionally a binding to search in, find and return the requested method wrapped in a `Pry::Method` instance.

@param [String, nil] name The name of the method to retrieve, or `nil` to

  delegate to `from_binding` instead.

@param [Binding] target The context in which to search for the method. @param [Hash] options @option options [Boolean] :instance Look for an instance method if `name` doesn‘t

  contain any context.

@option options [Boolean] :methods Look for a bound/singleton method if `name` doesn‘t

  contain any context.

@return [Pry::Method, nil] A `Pry::Method` instance containing the requested

  method, or `nil` if no method could be located matching the parameters.

Get every `Class` and `Module`, in order, that will be checked when looking for methods on instances of the given `Class` or `Module`. This does not treat singleton classes of classes specially. @param [Class, Module] klass @return [Array[Class, Module]]

A new instance of `Pry::Method` wrapping the given `::Method`, `UnboundMethod`, or `Proc`.

@param [::Method, UnboundMethod, Proc] method @param [Hash] known_info Can be used to pre-cache expensive to compute stuff. @return [Pry::Method]

Get every `Class` and `Module`, in order, that will be checked when looking for an instance method to call on this object. @param [Object] obj @return [Array[Class, Module]]

Acts like send but ignores any methods defined below Object or Class in the inheritance hierarchy. This is required to introspect methods on objects like Net::HTTP::Get that have overridden the `method` method.

Public Instance methods

@return [Boolean]

@return [Boolean] Is the method definitely an alias?

@return [String, nil] The documentation for the method, or `nil` if it‘s

  unavailable.

@raise [CommandError] Raises when the method was defined in the REPL.

@return [Boolean] Was the method defined outside a source file?

@param [Class] klass @return [Boolean]

kind_of?(klass)

Alias for is_a?

Delegate any unknown calls to the wrapped method.

Get the name of the method as a String, regardless of the underlying Method#name type. @return [String]

Get the name of the method including the class on which it was defined. @example

  method(:puts).method_name
  => "Kernel.puts"

@return [String]

@return [String, nil] The original name the method was defined under,

  before any aliasing, or `nil` if it can't be determined.

@return [Boolean] Was the method defined within the Pry REPL?

@param [String, Symbol] method_name @return [Boolean]

@return [String] A representation of the method‘s signature, including its

  name and parameters. Optional and "rest" parameters are marked with `*`
  and block parameters with `&`. If the parameter names are unavailable,
  they're given numbered names instead.
  Paraphrased from `awesome_print` gem.

@return [String, nil] The source code of the method, or `nil` if it‘s unavailable.

Can we get the source code for this method? @return [Boolean]

@return [String, nil] The name of the file the method is defined in, or

  `nil` if the filename is unavailable.

@return [Fixnum, nil] The line of code in `source_file` which begins

  the method's definition, or `nil` if that information is unavailable.

@return [Range, nil] The range of lines in `source_file` which contain

   the method's definition, or `nil` if that information is unavailable.

@return [Symbol] The source type of the method. The options are

  `:ruby` for Ruby methods or `:c` for methods written in C.

@return [Pry::Method, nil] The wrapped method that is called when you

  use "super" in the body of this method.

Is the method undefined? (aka `Disowned`) @return [Boolean] false

@return [Symbol] The visibility of the method. May be `:public`,

  `:protected`, or `:private`.

Get the owner of the method as a Pry::Module @return [Pry::Module]

[Validate]