1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge pull request #1082 from yui-knk/refactor-Method.from_str

Refactor Pry::Method.from_str , because of comment on method_or_class_lo...
This commit is contained in:
Robert 2014-02-02 18:46:19 -08:00
commit ba3fb3bc7c
2 changed files with 3 additions and 10 deletions

View file

@ -112,12 +112,6 @@ class Pry
end
def method_or_class_lookup
# we need this here because stupid Pry::Method.from_str() does a
# Pry::Method.from_binding when str is nil.
# Once we refactor Pry::Method.from_str() so it doesnt lookup
# from bindings, we can get rid of this check
return nil if str.to_s.empty?
obj = case str
when /\S+\(\)\z/
Pry::Method.from_str(str.sub(/\(\)\z/, ''),target) || Pry::WrappedModule.from_str(str, target)

View file

@ -31,8 +31,7 @@ class Pry
# 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 [String] name The name of the method to retrieve.
# @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
@ -40,10 +39,10 @@ class Pry
# @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.
# method, or `nil` if name is `nil` or no method could be located matching the parameters.
def from_str(name, target=TOPLEVEL_BINDING, options={})
if name.nil?
from_binding(target)
nil
elsif name.to_s =~ /(.+)\#(\S+)\Z/
context, meth_name = $1, $2
from_module(target.eval(context), meth_name, target)