diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 197889ae..b9fb4c81 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -28,7 +28,7 @@ class Pry def input_type(input,target) if input == "" :blank - elsif target.eval("defined? #{input} ") =~ /variable/ && + elsif target.eval("defined? #{input} ") =~ /variable|constant/ && target.eval(input).respond_to?(:source_location) :sourcable_object 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 :a, :all, "Show docs for all definitions and monkeypatches of the module/class" end - + def process_sourcable_object name = args.first object = target.eval(name) diff --git a/test/test_default_commands/test_show_source.rb b/test/test_default_commands/test_show_source.rb index b379239b..68248344 100644 --- a/test/test_default_commands/test_show_source.rb +++ b/test/test_default_commands/test_show_source.rb @@ -206,11 +206,17 @@ if !mri18_and_no_real_source_location? 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!' } mock_pry(binding, "show-source hello").should =~ /proc { puts 'hello world!' }/ 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 def @o.hi; puts 'hi world'; end meth = @o.method(:hi)