From 137cc249174cee09c89c68c1f91d7341ea626036 Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 5 Apr 2011 00:18:07 +1200 Subject: [PATCH] added BasicObject support (class not instances). And support inspecting objects without to_s and inspect by defaulting to 'unknown'. Also slightly refactored tests, moved more stuff into test_helper. --- lib/pry/pry_class.rb | 3 +++ lib/pry/pry_instance.rb | 12 ++++++------ test/test.rb | 6 ------ test/test_helper.rb | 5 +++++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 5a9a541d..b0a072ef 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -122,6 +122,9 @@ class Pry else obj.to_s end + + rescue NoMethodError + "unknown" end # A version of `Pry.view` that clips the output to `max_size` chars. diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index c217ef6e..bc0f4927 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -71,8 +71,8 @@ class Pry Pry.active_instance = self # Make sure special locals exist - target.eval("_pry_ = Pry.active_instance") - target.eval("_ = Pry.last_result") + target.eval("_pry_ = ::Pry.active_instance") + target.eval("_ = ::Pry.last_result") self.session_target = target end @@ -155,7 +155,7 @@ class Pry # save the pry instance to active_instance Pry.active_instance = self - target.eval("_pry_ = Pry.active_instance") + target.eval("_pry_ = ::Pry.active_instance") # eval the expression and save to last_result # Do not want __FILE__, __LINE__ here because we need to distinguish @@ -228,7 +228,7 @@ class Pry # @param [Binding] target The binding to set `_` on. def set_last_result(result, target) Pry.last_result = result - target.eval("_ = Pry.last_result") + target.eval("_ = ::Pry.last_result") end # Set the last exception for a session. @@ -237,7 +237,7 @@ class Pry # @param [Binding] target The binding to set `_ex_` on. def set_last_exception(ex, target) Pry.last_exception = ex - target.eval("_ex_ = Pry.last_exception") + target.eval("_ex_ = ::Pry.last_exception") end # Determine whether a Pry command was matched and return command data @@ -355,7 +355,7 @@ class Pry end end - if RUBY_VERSION =~ /1.9/ + if RUBY_VERSION =~ /1.9/ && RUBY_ENGINE == "ruby" require 'ripper' # Determine if a string of code is a valid Ruby expression. diff --git a/test/test.rb b/test/test.rb index 8dc41f16..074d9c90 100644 --- a/test/test.rb +++ b/test/test.rb @@ -10,15 +10,9 @@ puts "Testing Pry #{Pry::VERSION}" puts "With method_source version #{MethodSource::VERSION}" puts "--" -# Ensure we do not execute any rc files -Pry::RC_FILES.clear -Pry.color = false -Pry.should_load_rc = false - describe Pry do describe "open a Pry session on an object" do describe "rep" do - before do class Hello end diff --git a/test/test_helper.rb b/test/test_helper.rb index dd48c466..3d5587f1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,8 @@ +# Ensure we do not execute any rc files +Pry::RC_FILES.clear +Pry.color = false +Pry.should_load_rc = false + class Module public :remove_const end