diff --git a/lib/pry/commands/edit/file_and_line_locator.rb b/lib/pry/commands/edit/file_and_line_locator.rb index 15eed632..db56cd3c 100644 --- a/lib/pry/commands/edit/file_and_line_locator.rb +++ b/lib/pry/commands/edit/file_and_line_locator.rb @@ -3,7 +3,11 @@ class Pry module FileAndLineLocator class << self def from_binding(target) - [target.eval("__FILE__"), target.eval("__LINE__")] + if target.respond_to?(:source_location) + target.source_location + else + [target.eval("__FILE__"), target.eval("__LINE__")] + end end def from_code_object(code_object, filename_argument) diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb index cb60fb61..d16244ea 100644 --- a/lib/pry/commands/play.rb +++ b/lib/pry/commands/play.rb @@ -86,7 +86,13 @@ class Pry # The file to play from when no code object is specified. # e.g `play --lines 4..10` def default_file - target.eval("__FILE__") && File.expand_path(target.eval("__FILE__")) + file = + if target.respond_to?(:source_location) + target.source_location.first + else + target.eval("__FILE__") + end + file && File.expand_path(file) end def file_content diff --git a/lib/pry/commands/reload_code.rb b/lib/pry/commands/reload_code.rb index 311ae8ec..5811fe5c 100644 --- a/lib/pry/commands/reload_code.rb +++ b/lib/pry/commands/reload_code.rb @@ -27,7 +27,13 @@ class Pry private def current_file - File.expand_path target.eval("__FILE__") + file = + if target.respond_to?(:source_location) + target.source_location.first + else + target.eval("__FILE__") + end + File.expand_path file end def reload_current_file diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index 4462e293..45d63c06 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -37,8 +37,13 @@ class Pry BANNER def setup - @file = expand_path(target.eval('__FILE__')) - @line = target.eval('__LINE__') + if target.respond_to?(:source_location) + file, @line = target.source_location + @file = expand_path(file) + else + @file = expand_path(target.eval('__FILE__')) + @line = target.eval('__LINE__') + end @method = Pry::Method.from_binding(target) end diff --git a/lib/pry/method/weird_method_locator.rb b/lib/pry/method/weird_method_locator.rb index 8150b59c..a3aa109a 100644 --- a/lib/pry/method/weird_method_locator.rb +++ b/lib/pry/method/weird_method_locator.rb @@ -25,7 +25,11 @@ class Pry # @return [Boolean] def normal_method?(method, b) if method && method.source_file && method.source_range - binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__') + if b.respond_to?(:source_location) + binding_file, binding_line = b.source_location + else + binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__') + end (File.expand_path(method.source_file) == File.expand_path(binding_file)) && method.source_range.include?(binding_line) end @@ -77,15 +81,31 @@ class Pry end def target_file - pry_file? ? target.eval('__FILE__') : File.expand_path(target.eval('__FILE__')) + file = + if target.respond_to?(:source_location) + target.source_location.first + else + target.eval('__FILE__') + end + pry_file? ? file : File.expand_path(file) end def target_line - target.eval('__LINE__') + if target.respond_to?(:source_location) + target.source_location.last + else + target.eval('__LINE__') + end end def pry_file? - Pry.eval_path == target.eval('__FILE__') + file = + if target.respond_to?(:source_location) + target.source_location.first + else + target.eval('__FILE__') + end + Pry.eval_path == file end # it's possible in some cases that the method we find by this approach is a sub-method of