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

Merge pull request #358 from KL-7/master

Fix for issue #357. The easy way.
This commit is contained in:
John Mair 2011-11-30 21:57:20 -08:00
commit ab458ff1f9
2 changed files with 10 additions and 6 deletions

View file

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

View file

@ -45,7 +45,7 @@ class Pry
# @return [Pry::Method, nil] # @return [Pry::Method, nil]
# #
def from_binding(b) 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) if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
nil nil
else else
@ -113,6 +113,14 @@ class Pry
([klass] + klass.ancestors).uniq ([klass] + klass.ancestors).uniq
end 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 private
# See all_from_class and all_from_obj. # See all_from_class and all_from_obj.