Skip to content

Commit 6615b62

Browse files
committed
Refine Set#pretty_print check
1 parent 99064d2 commit 6615b62

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/pp.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ def pretty_print_cycle(q) # :nodoc:
443443
end
444444
end
445445

446+
if defined?(Set)
447+
if set_pp = Set.instance_method(:initialize).source_location
448+
set_pp = !set_pp.first.end_with?("/set.rb") # not defined in set.rb
449+
else
450+
set_pp = true # defined in C
451+
end
452+
end
446453
class Set # :nodoc:
447454
def pretty_print(pp) # :nodoc:
448455
pp.group(1, '#<Set:', '>') {
@@ -453,12 +460,12 @@ def pretty_print(pp) # :nodoc:
453460
}
454461
}
455462
}
456-
end unless method_defined?(:pretty_print)
463+
end
457464

458465
def pretty_print_cycle(pp) # :nodoc:
459466
pp.text sprintf('#<Set: {%s}>', empty? ? '' : '...')
460-
end unless method_defined?(:pretty_print_cycle)
461-
end
467+
end
468+
end if set_pp
462469

463470
class << ENV # :nodoc:
464471
def pretty_print(q) # :nodoc:

0 commit comments

Comments
 (0)