diff --git a/lib/pp.rb b/lib/pp.rb index 1ec5a88..d3f0f78 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -189,7 +189,7 @@ def pop_inspect_key(id) 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 @@ def pp(obj) 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 2fdd5df..45c7691 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -125,6 +125,11 @@ def a.to_s() "aaa" end 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