summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2025-10-04 15:30:47 +0200
committerNobuyoshi Nakada <nobu@ruby-lang.org>2025-10-05 15:13:52 +0900
commit340777078c88478bae1e39b10bd6409491fd584b (patch)
tree835d5113156b2254bed3e9aeaa2b385dd32145fa
parent80a18e8f422e30204e7386fc9a1fc37667b20b2a (diff)
[ruby/pp] Fix ::Data warning on Ruby 2.7
* It was showing on require 'pp': lib/pp.rb:525: warning: constant ::Data is deprecated * Fixes https://github.com/ruby/pp/issues/51 https://github.com/ruby/pp/commit/4fd8f4e0bb
-rw-r--r--lib/pp.rb9
-rw-r--r--test/test_pp.rb9
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index eb9f80db4e..f10fe7f2f0 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -490,6 +490,13 @@ class Struct # :nodoc:
end
end
+verbose, $VERBOSE = $VERBOSE, nil
+begin
+ has_data_define = defined?(Data.define)
+ensure
+ $VERBOSE = verbose
+end
+
class Data # :nodoc:
def pretty_print(q) # :nodoc:
class_name = PP.mcall(self, Kernel, :class).name
@@ -522,7 +529,7 @@ class Data # :nodoc:
def pretty_print_cycle(q) # :nodoc:
q.text sprintf("#<data %s:...>", PP.mcall(self, Kernel, :class).name)
end
-end if defined?(Data.define)
+end if has_data_define
class Range # :nodoc:
def pretty_print(q) # :nodoc:
diff --git a/test/test_pp.rb b/test/test_pp.rb
index e721260e01..28da00e3e7 100644
--- a/test/test_pp.rb
+++ b/test/test_pp.rb
@@ -172,7 +172,14 @@ class PPCycleTest < Test::Unit::TestCase
assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) unless RUBY_ENGINE == "truffleruby"
end
- if defined?(Data.define)
+ verbose, $VERBOSE = $VERBOSE, nil
+ begin
+ has_data_define = defined?(Data.define)
+ ensure
+ $VERBOSE = verbose
+ end
+
+ if has_data_define
D = Data.define(:aaa, :bbb)
def test_data
a = D.new("aaa", "bbb")