From 1ed3b6037566cef3d56e882eb0fcf1b14553f540 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 30 Nov 2023 17:10:40 +0100 Subject: [PATCH] [ruby/pp] Fix pretty printing a Data subclass instance when the subclass is anonymous * It would be "#" (double space) instead of "#" (like #inspect). https://github.com/ruby/pp/commit/bed72bfcb8 --- lib/pp.rb | 4 +++- test/test_pp.rb | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pp.rb b/lib/pp.rb index 5e5fd06cae..fb7aa7b41c 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -422,7 +422,9 @@ end class Data # :nodoc: def pretty_print(q) # :nodoc: - q.group(1, sprintf("#') { + class_name = PP.mcall(self, Kernel, :class).name + class_name = " #{class_name}" if class_name + q.group(1, "#') { q.seplist(PP.mcall(self, Kernel, :class).members, lambda { q.text "," }) {|member| q.breakable q.text member.to_s diff --git a/test/test_pp.rb b/test/test_pp.rb index d7cca82a00..72a4f127f3 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -149,6 +149,9 @@ class PPCycleTest < Test::Unit::TestCase a = D.new("aaa", "bbb") assert_equal("#\n", PP.pp(a, ''.dup, 20)) assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) + + b = Data.define(:a).new(42) + assert_equal("#{b.inspect}\n", PP.pp(b, ''.dup)) end end