Skip to content

Commit c8ae2c5

Browse files
authored
Merge pull request #789 from byroot/deprecated-pretty-prototype
Bring back JSON::PRETTY_STATE_PROTOTYPE with a deprecation
2 parents 84443e8 + 123121b commit c8ae2c5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changes
22

3+
* Add back `JSON::PRETTY_STATE_PROTOTYPE`. This constant was private API but is used by popular gems like `multi_json`.
4+
It now emits a deprecation warning.
5+
36
### 2025-04-24 (2.11.1)
47

58
* Add back `JSON.restore`, `JSON.unparse`, `JSON.fast_unparse` and `JSON.pretty_unparse`.

lib/json/common.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,24 @@ def restore(...)
961961
load(...)
962962
end
963963
module_function :restore
964+
965+
class << self
966+
private
967+
968+
def const_missing(const_name)
969+
case const_name
970+
when :PRETTY_STATE_PROTOTYPE
971+
if RUBY_VERSION >= "3.0"
972+
warn "JSON::PRETTY_STATE_PROTOTYPE is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated
973+
else
974+
warn "JSON::PRETTY_STATE_PROTOTYPE is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1
975+
end
976+
state.new(PRETTY_GENERATE_OPTIONS)
977+
else
978+
super
979+
end
980+
end
981+
end
964982
# :startdoc:
965983

966984
# JSON::Coder holds a parser and generator configuration.

0 commit comments

Comments
 (0)