diff --git a/lib/pp.rb b/lib/pp.rb index 2adceea3e2..4bb1002f7b 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -189,7 +189,7 @@ class PP < PrettyPrint def pp(obj) # If obj is a Delegator then use the object being delegated to for cycle # detection - obj = obj.__getobj__ if defined?(::Delegator) and obj.is_a?(::Delegator) + obj = obj.__getobj__ if defined?(::Delegator) and ::Delegator === obj if check_inspect_key(obj) group {obj.pretty_print_cycle self} @@ -198,7 +198,11 @@ class PP < PrettyPrint begin push_inspect_key(obj) - group {obj.pretty_print self} + group do + obj.pretty_print self + rescue NoMethodError + text Kernel.instance_method(:inspect).bind_call(obj) + end ensure pop_inspect_key(obj) unless PP.sharing_detection end diff --git a/test/test_pp.rb b/test/test_pp.rb index e515e920dc..16f6fa7485 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -125,6 +125,11 @@ class PPInspectTest < Test::Unit::TestCase result = PP.pp(a, ''.dup) assert_equal("#{a.inspect}\n", result) end + + def test_basic_object + a = BasicObject.new + assert_match(/\A#\n\z/, PP.pp(a, ''.dup)) + end end class PPCycleTest < Test::Unit::TestCase