Skip to content

Commit 3407770

Browse files
eregonnobu
authored andcommitted
[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 ruby/pp#51 ruby/pp@4fd8f4e0bb
1 parent 80a18e8 commit 3407770

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/pp.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ def pretty_print_cycle(q) # :nodoc:
490490
end
491491
end
492492

493+
verbose, $VERBOSE = $VERBOSE, nil
494+
begin
495+
has_data_define = defined?(Data.define)
496+
ensure
497+
$VERBOSE = verbose
498+
end
499+
493500
class Data # :nodoc:
494501
def pretty_print(q) # :nodoc:
495502
class_name = PP.mcall(self, Kernel, :class).name
@@ -522,7 +529,7 @@ def pretty_print(q) # :nodoc:
522529
def pretty_print_cycle(q) # :nodoc:
523530
q.text sprintf("#<data %s:...>", PP.mcall(self, Kernel, :class).name)
524531
end
525-
end if defined?(Data.define)
532+
end if has_data_define
526533

527534
class Range # :nodoc:
528535
def pretty_print(q) # :nodoc:

test/test_pp.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,14 @@ def test_struct
172172
assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) unless RUBY_ENGINE == "truffleruby"
173173
end
174174

175-
if defined?(Data.define)
175+
verbose, $VERBOSE = $VERBOSE, nil
176+
begin
177+
has_data_define = defined?(Data.define)
178+
ensure
179+
$VERBOSE = verbose
180+
end
181+
182+
if has_data_define
176183
D = Data.define(:aaa, :bbb)
177184
def test_data
178185
a = D.new("aaa", "bbb")

0 commit comments

Comments
 (0)