Skip to content

Commit 3187c88

Browse files
committed
Improve generation options documentation
1 parent 19bcfdd commit 3187c88

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Gemfile.lock
2121
.byebug_history
2222
*.log
2323
/tmp
24-
24+
/doc/

lib/json.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@
307307
#
308308
# ---
309309
#
310+
# Option +allow_duplicate_key+ (boolean) specifies whether
311+
# hashes with duplicate keys should be allowed or produce an error.
312+
# defaults to emit a deprecation warning.
313+
#
314+
# With the default, (not set):
315+
# Warning[:deprecated] = true
316+
# JSON.generate({ foo: 1, "foo" => 2 })
317+
# # warning: detected duplicate key "foo" in {foo: 1, "foo" => 2}.
318+
# # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
319+
# # => '{"foo":1,"foo":2}'
320+
#
321+
# With <tt>false</tt>
322+
# JSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: false)
323+
# # detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
324+
#
325+
# In version 3.0, <tt>false</tt> will become the default.
326+
#
327+
# ---
328+
#
310329
# Option +max_nesting+ (\Integer) specifies the maximum nesting depth
311330
# in +obj+; defaults to +100+.
312331
#
@@ -384,6 +403,9 @@
384403
#
385404
# == \JSON Additions
386405
#
406+
# Note that JSON Additions must only be used with trusted data, and is
407+
# deprecated.
408+
#
387409
# When you "round trip" a non-\String object from Ruby to \JSON and back,
388410
# you have a new \String, instead of the object you began with:
389411
# ruby0 = Range.new(0, 2)

lib/json/ext/generator/state.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,8 @@ class State
88
#
99
# Instantiates a new State object, configured by _opts_.
1010
#
11-
# _opts_ can have the following keys:
12-
#
13-
# * *indent*: a string used to indent levels (default: ''),
14-
# * *space*: a string that is put after, a : or , delimiter (default: ''),
15-
# * *space_before*: a string that is put before a : pair delimiter (default: ''),
16-
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
17-
# * *array_nl*: a string that is put at the end of a JSON array (default: ''),
18-
# * *allow_nan*: true if NaN, Infinity, and -Infinity should be
19-
# generated, otherwise an exception is thrown, if these values are
20-
# encountered. This options defaults to false.
21-
# * *ascii_only*: true if only ASCII characters should be generated. This
22-
# option defaults to false.
23-
# * *buffer_initial_length*: sets the initial length of the generator's
24-
# internal buffer.
11+
# Argument +opts+, if given, contains a \Hash of options for the generation.
12+
# See {Generating Options}[#module-JSON-label-Generating+Options].
2513
def initialize(opts = nil)
2614
if opts && !opts.empty?
2715
configure(opts)

0 commit comments

Comments
 (0)