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

Allow pry commands to work even when #call is defined on Symbol.

When #call is defined on Symbol, Slop (3.6.0) fails.
This commit is contained in:
egwspiti 2015-06-30 20:47:38 +03:00
parent f117fded1c
commit 31ec9f13bc
2 changed files with 22 additions and 1 deletions

View file

@ -427,10 +427,20 @@ class Pry
raise CommandError, "The command '#{command_name}' requires an argument."
end
ret = call_with_hooks(*args)
ret = use_unpatched_symbol do
call_with_hooks(*args)
end
command_options[:keep_retval] ? ret : void
end
def use_unpatched_symbol
call_method = Symbol.method_defined?(:call) && Symbol.instance_method(:call)
Symbol.class_eval { undef :call } if call_method
yield
ensure
Symbol.instance_eval { define_method(:call, call_method) } if call_method
end
# Are all the gems required to use this command installed?
#
# @return Boolean

View file

@ -14,6 +14,17 @@ describe "show-doc" do
end
after do
if Symbol.method_defined? :call
Symbol.class_eval { undef :call }
end
end
it 'should work even if #call is defined on Symbol' do
class Symbol ; def call ; 5 ; end ; end
expect(pry_eval(binding, "show-doc @o.sample_method")).to match(/sample doc/)
end
it 'should output a method\'s documentation' do
expect(pry_eval(binding, "show-doc @o.sample_method")).to match(/sample doc/)
end