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.
This commit is contained in:
John Mair 2011-04-05 00:18:07 +12:00
parent 0fa6fdce5e
commit 137cc24917
4 changed files with 14 additions and 12 deletions

View File

@ -122,6 +122,9 @@ class Pry
else else
obj.to_s obj.to_s
end end
rescue NoMethodError
"unknown"
end end
# A version of `Pry.view` that clips the output to `max_size` chars. # A version of `Pry.view` that clips the output to `max_size` chars.

View File

@ -71,8 +71,8 @@ class Pry
Pry.active_instance = self Pry.active_instance = self
# Make sure special locals exist # Make sure special locals exist
target.eval("_pry_ = Pry.active_instance") target.eval("_pry_ = ::Pry.active_instance")
target.eval("_ = Pry.last_result") target.eval("_ = ::Pry.last_result")
self.session_target = target self.session_target = target
end end
@ -155,7 +155,7 @@ class Pry
# save the pry instance to active_instance # save the pry instance to active_instance
Pry.active_instance = self Pry.active_instance = self
target.eval("_pry_ = Pry.active_instance") target.eval("_pry_ = ::Pry.active_instance")
# eval the expression and save to last_result # eval the expression and save to last_result
# Do not want __FILE__, __LINE__ here because we need to distinguish # 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. # @param [Binding] target The binding to set `_` on.
def set_last_result(result, target) def set_last_result(result, target)
Pry.last_result = result Pry.last_result = result
target.eval("_ = Pry.last_result") target.eval("_ = ::Pry.last_result")
end end
# Set the last exception for a session. # Set the last exception for a session.
@ -237,7 +237,7 @@ class Pry
# @param [Binding] target The binding to set `_ex_` on. # @param [Binding] target The binding to set `_ex_` on.
def set_last_exception(ex, target) def set_last_exception(ex, target)
Pry.last_exception = ex Pry.last_exception = ex
target.eval("_ex_ = Pry.last_exception") target.eval("_ex_ = ::Pry.last_exception")
end end
# Determine whether a Pry command was matched and return command data # Determine whether a Pry command was matched and return command data
@ -355,7 +355,7 @@ class Pry
end end
end end
if RUBY_VERSION =~ /1.9/ if RUBY_VERSION =~ /1.9/ && RUBY_ENGINE == "ruby"
require 'ripper' require 'ripper'
# Determine if a string of code is a valid Ruby expression. # Determine if a string of code is a valid Ruby expression.

View File

@ -10,15 +10,9 @@ puts "Testing Pry #{Pry::VERSION}"
puts "With method_source version #{MethodSource::VERSION}" puts "With method_source version #{MethodSource::VERSION}"
puts "--" 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 Pry do
describe "open a Pry session on an object" do describe "open a Pry session on an object" do
describe "rep" do describe "rep" do
before do before do
class Hello class Hello
end end

View File

@ -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 class Module
public :remove_const public :remove_const
end end