From 6615b62d7b269391cff131f00ac2754808936c46 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 5 Oct 2025 00:52:32 +0900 Subject: [PATCH] Refine `Set#pretty_print` check --- lib/pp.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pp.rb b/lib/pp.rb index 0e55441..ed801f0 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -443,6 +443,13 @@ def pretty_print_cycle(q) # :nodoc: end end +if defined?(Set) + if set_pp = Set.instance_method(:initialize).source_location + set_pp = !set_pp.first.end_with?("/set.rb") # not defined in set.rb + else + set_pp = true # defined in C + end +end class Set # :nodoc: def pretty_print(pp) # :nodoc: pp.group(1, '#') { @@ -453,12 +460,12 @@ def pretty_print(pp) # :nodoc: } } } - end unless method_defined?(:pretty_print) + end def pretty_print_cycle(pp) # :nodoc: pp.text sprintf('#', empty? ? '' : '...') - end unless method_defined?(:pretty_print_cycle) -end + end +end if set_pp class << ENV # :nodoc: def pretty_print(q) # :nodoc: