diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index e4b3e132..655209ad 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -21,15 +21,14 @@ class Pry BANNER def setup + @method = Pry::Method.from_binding(target) if internal_binding?(target) location = _pry_.backtrace.detect do |x| !x.start_with?(File.expand_path('../../../../lib', __FILE__)) end - @method = nil @file = location.split(":").first @line = location.split(":")[1].to_i else - @method = Pry::Method.from_binding(target) @file = target.eval('__FILE__') @line = target.eval('__LINE__') end @@ -52,11 +51,13 @@ class Pry end def process - if opts.quiet? && (at_top_level? || !code?) - return - elsif at_top_level? - output.puts "At the top level." + if opts.quiet? && (internal_binding?(target) || !code?) return + elsif internal_binding?(target) + if @file.end_with?("bin/pry") + output.puts "At the top level." + return + end end set_file_and_dir_locals(@file) @@ -68,10 +69,6 @@ class Pry private - def at_top_level? - @file.end_with?("bin/pry") - end - def show_method? args.empty? && @method && @method.source? && @method.source_range.count < 20 && # These checks are needed in case of an eval with a binding and file/line diff --git a/spec/commands/whereami_spec.rb b/spec/commands/whereami_spec.rb index 29705690..04855d1a 100644 --- a/spec/commands/whereami_spec.rb +++ b/spec/commands/whereami_spec.rb @@ -128,15 +128,15 @@ describe "whereami" do end it "should work at the top level" do - pry_eval(Pry.toplevel_binding, 'whereami', :backtrace => ['bin/pry:5:__foo__']).should =~ + pry_eval(Pry.toplevel_binding, 'whereami').should =~ /At the top level/ end it "should work inside a class" do - pry_eval(Pry, 'whereami', :backtrace => ['spec/fixtures/example.erb:5:__foo__']).should =~ /example.erb/ + pry_eval(Pry, 'whereami').should =~ /Inside Pry/ end it "should work inside an object" do - pry_eval(Object.new, 'whereami', :backtrace => ['spec/fixtures/example.erb:5:bar']).should =~ /example.erb/ + pry_eval(Object.new, 'whereami').should =~ /Inside #