From d593294bfe9c888b5dc7e981d0c3a01071cb9c42 Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 25 May 2011 12:48:53 +1200 Subject: [PATCH] replaced explicit '(pry)' string with Pry.eval_path method --- lib/pry/helpers/command_helpers.rb | 4 ++-- lib/pry/pry_class.rb | 5 +++++ lib/pry/pry_instance.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index dbd87688..041e76e4 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -43,7 +43,7 @@ class Pry def check_for_dynamically_defined_method(meth) file, _ = meth.source_location - if file =~ /(\(.*\))|<.*>/ && file != "(pry)" + if file =~ /(\(.*\))|<.*>/ && file != Pry.eval_path raise "Cannot retrieve source for dynamically defined method." end end @@ -61,7 +61,7 @@ class Pry code = Pry::MethodInfo.info_for(meth).source code = strip_comments_from_c_code(code) when :ruby - if meth.source_location.first == "(pry)" + if meth.source_location.first == Pry.eval_path start_line = meth.source_location.last p = Pry.new(:input => StringIO.new(Pry.line_buffer[start_line..-1].join)).r(target) diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 66059a36..0a6fdc30 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -122,6 +122,10 @@ class Pry # @return [Array] The Array of evaluated expressions. attr_accessor :line_buffer + # @return [String] The __FILE__ for the `eval()`. Should be "(pry)" + # by default. + attr_accessor :eval_path + # plugin forwardables def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins @@ -255,6 +259,7 @@ class Pry @cli = false @current_line = 0 @line_buffer = [] + @eval_path = "(pry)" end # Basic initialization. diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index ac569fed..5c6ff464 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -187,7 +187,7 @@ class Pry expr = r(target) Pry.line_buffer.push(*expr.each_line) - set_last_result(target.eval(expr, "(pry)", Pry.current_line), target) + set_last_result(target.eval(expr, Pry.eval_path, Pry.current_line), target) rescue SystemExit => e exit rescue Exception => e