-
-
Save banister/7941d1a83987f2d39c9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
def from_str(name, target=TOPLEVEL_BINDING, options={}) | |
if name.nil? | |
from_binding(target) | |
elsif name.to_s =~ /(.+)\#(\S+)\Z/ | |
context, meth_name = $1, $2 | |
from_module(target.eval(context), meth_name, target) | |
elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/ | |
context, meth_name = $1, $3 | |
from_obj(target.eval(context), meth_name, target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment