Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/test_pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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#<BasicObject:0x[\da-f]+>\n\z/, PP.pp(a, ''.dup))
end
end

class PPCycleTest < Test::Unit::TestCase
Expand Down