Skip to content

Commit 27155b6

Browse files
committed
Deprecate Kernel#j and Kernel#jj
1 parent 3e7e661 commit 27155b6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Deprecate `JSON.load_default_options`.
99
* Deprecate `JSON.unsafe_load_default_options`.
1010
* Deprecate `JSON.dump_default_options`.
11+
* Deprecate `Kernel#j`
12+
* Deprecate `Kernel#jj`
1113
* Remove outdated `JSON.iconv`.
1214
* Remove `Class#json_creatable?` monkey patch.
1315
* Remove deprecated `JSON.restore` method.

lib/json/common.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,12 @@ module ::Kernel
10051005
# Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
10061006
# one line.
10071007
def j(*objs)
1008+
if RUBY_VERSION >= "3.0"
1009+
warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
1010+
else
1011+
warn "Kernel#j is deprecated and will be removed in json 3.0.0", uplevel: 1
1012+
end
1013+
10081014
objs.each do |obj|
10091015
puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
10101016
end
@@ -1014,6 +1020,12 @@ def j(*objs)
10141020
# Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
10151021
# indentation and over many lines.
10161022
def jj(*objs)
1023+
if RUBY_VERSION >= "3.0"
1024+
warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1, category: :deprecated
1025+
else
1026+
warn "Kernel#jj is deprecated and will be removed in json 3.0.0", uplevel: 1
1027+
end
1028+
10171029
objs.each do |obj|
10181030
puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
10191031
end

0 commit comments

Comments
 (0)