diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2012-11-18 03:53:35 -0800 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2012-11-18 03:54:04 -0800 |
commit | 2e8881f59e2a9b2879194490bcd93cde4926fc22 (patch) | |
tree | 0707202fe1df3b6bacc1e56b9af474513fbe6b37 | |
parent | a15d134e60e1502f160322abb99b5a5b1394b9cf (diff) | |
download | pry-2e8881f59e2a9b2879194490bcd93cde4926fc22.tar.gz |
make whereami more consistent [Fixes #383]
-rw-r--r-- | lib/pry/commands/whereami.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index 121e642b..655209ad 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -22,8 +22,16 @@ class Pry def setup @method = Pry::Method.from_binding(target) - @file = target.eval('__FILE__') - @line = target.eval('__LINE__') + if internal_binding?(target) + location = _pry_.backtrace.detect do |x| + !x.start_with?(File.expand_path('../../../../lib', __FILE__)) + end + @file = location.split(":").first + @line = location.split(":")[1].to_i + else + @file = target.eval('__FILE__') + @line = target.eval('__LINE__') + end end def options(opt) @@ -46,12 +54,10 @@ class Pry if opts.quiet? && (internal_binding?(target) || !code?) return elsif internal_binding?(target) - if target_self == TOPLEVEL_BINDING.eval("self") + if @file.end_with?("bin/pry") output.puts "At the top level." - else - output.puts "Inside #{Pry.view_clip(target_self)}." + return end - return end set_file_and_dir_locals(@file) |