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

Fetch method name for 'whereami' directly from binding.

Pry::Method.from_str fails to find by name unbound method that was
removed from the class. As 'whereami' command needs only name of the
method it can fetch that name directly from binding without performing
lookup of the method itself.
This commit is contained in:
Kirill Lashuk 2011-11-30 01:54:55 +03:00
parent 28560c0d73
commit a9db4054db
2 changed files with 10 additions and 6 deletions

View file

@ -143,11 +143,7 @@ class Pry
i_num = 5
end
if (meth = Pry::Method.from_binding(target))
meth_name = meth.name
else
meth_name = "N/A"
end
meth_name = Pry::Method.method_name_from_binding(target) || "N/A"
if file != Pry.eval_path && (file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e")
raise CommandError, "Cannot find local context. Did you use `binding.pry`?"

View file

@ -45,7 +45,7 @@ class Pry
# @return [Pry::Method, nil]
#
def from_binding(b)
meth_name = b.eval('__method__')
meth_name = method_name_from_binding(b)
if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
nil
else
@ -113,6 +113,14 @@ class Pry
([klass] + klass.ancestors).uniq
end
# Given a `Binding` extract name of the method it originated from.
# Return `nil` if no such method exists.
# @param [Binding] b
# @return [Symbol, nil]
def method_name_from_binding(b)
b.eval('__method__')
end
private
# See all_from_class and all_from_obj.