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

Enable show-source for procs stored in constants

This commit is contained in:
Reginald Tan 2012-07-26 15:17:08 -04:00
parent eb73b23245
commit 2366446430
2 changed files with 9 additions and 3 deletions

View file

@ -28,7 +28,7 @@ class Pry
def input_type(input,target) def input_type(input,target)
if input == "" if input == ""
:blank :blank
elsif target.eval("defined? #{input} ") =~ /variable/ && elsif target.eval("defined? #{input} ") =~ /variable|constant/ &&
target.eval(input).respond_to?(:source_location) target.eval(input).respond_to?(:source_location)
:sourcable_object :sourcable_object
elsif Pry::Method.from_str(input,target) elsif Pry::Method.from_str(input,target)
@ -137,7 +137,7 @@ class Pry
opt.on :f, :flood, "Do not use a pager to view text longer than one screen." opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
opt.on :a, :all, "Show docs for all definitions and monkeypatches of the module/class" opt.on :a, :all, "Show docs for all definitions and monkeypatches of the module/class"
end end
def process_sourcable_object def process_sourcable_object
name = args.first name = args.first
object = target.eval(name) object = target.eval(name)

View file

@ -206,11 +206,17 @@ if !mri18_and_no_real_source_location?
end end
end end
it "should output source for procs/lambdas" do it "should output source for procs/lambdas stored in variables" do
hello = proc { puts 'hello world!' } hello = proc { puts 'hello world!' }
mock_pry(binding, "show-source hello").should =~ /proc { puts 'hello world!' }/ mock_pry(binding, "show-source hello").should =~ /proc { puts 'hello world!' }/
end end
it "should output source for procs/lambdas stored in constants" do
HELLO = proc { puts 'hello world!' }
mock_pry(binding, "show-source HELLO").should =~ /proc { puts 'hello world!' }/
Object.remove_const(:HELLO)
end
it "should output source for method objects" do it "should output source for method objects" do
def @o.hi; puts 'hi world'; end def @o.hi; puts 'hi world'; end
meth = @o.method(:hi) meth = @o.method(:hi)