rbs 3.9.4 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.clang-format +75 -0
- data/.clangd +2 -0
- data/.dockerignore +37 -0
- data/.github/dependabot.yml +16 -14
- data/.github/workflows/bundle-update.yml +63 -0
- data/.github/workflows/c-check.yml +66 -0
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/jruby.yml +79 -0
- data/.github/workflows/release-gems.yml +164 -0
- data/.github/workflows/ruby.yml +84 -30
- data/.github/workflows/rust.yml +186 -0
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +5 -2
- data/.github/workflows/wasm.yml +55 -0
- data/.github/workflows/windows.yml +9 -3
- data/.gitignore +16 -0
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +430 -0
- data/Dockerfile.jruby +53 -0
- data/README.md +41 -4
- data/Rakefile +777 -60
- data/Steepfile +11 -0
- data/config.yml +660 -62
- data/core/array.rbs +541 -398
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +9 -8
- data/core/class.rbs +11 -8
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +297 -196
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator/product.rbs +5 -5
- data/core/enumerator.rbs +91 -28
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +260 -1151
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -116
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1151 -829
- data/core/integer.rbs +156 -195
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +220 -154
- data/core/kernel.rbs +239 -163
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +16 -14
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +302 -150
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +77 -63
- data/core/object.rbs +9 -11
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1312 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +364 -518
- data/core/random.rbs +21 -3
- data/core/range.rbs +181 -79
- data/core/rational.rbs +60 -89
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +63 -56
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +78 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +6 -70
- data/core/rubygems/requirement.rbs +5 -15
- data/core/rubygems/rubygems.rbs +18 -81
- data/core/rubygems/specification.rbs +8 -0
- data/core/rubygems/version.rbs +2 -163
- data/core/set.rbs +493 -363
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +43 -42
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +139 -83
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +634 -0
- data/docs/rbs_by_example.md +20 -20
- data/docs/release.md +151 -0
- data/docs/rust.md +96 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +48 -18
- data/docs/type_fingerprint.md +21 -0
- data/docs/wasm_serialization.md +80 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +1855 -0
- data/ext/rbs_extension/ast_translation.h +41 -0
- data/ext/rbs_extension/class_constants.c +187 -0
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +23 -1
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +26 -1
- data/ext/rbs_extension/legacy_location.c +299 -0
- data/ext/rbs_extension/legacy_location.h +82 -0
- data/ext/rbs_extension/main.c +603 -23
- data/ext/rbs_extension/rbs_extension.h +6 -21
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +24 -0
- data/include/rbs/ast.h +1047 -0
- data/include/rbs/defines.h +99 -0
- data/include/rbs/lexer.h +207 -0
- data/include/rbs/location.h +40 -0
- data/include/rbs/parser.h +153 -0
- data/include/rbs/serialize.h +39 -0
- data/include/rbs/string.h +47 -0
- data/include/rbs/util/rbs_allocator.h +59 -0
- data/include/rbs/util/rbs_assert.h +20 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +6 -70
- data/include/rbs/util/rbs_encoding.h +282 -0
- data/include/rbs/util/rbs_unescape.h +24 -0
- data/include/rbs.h +9 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +30 -32
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +451 -0
- data/lib/rbs/ast/ruby/comment_block.rb +247 -0
- data/lib/rbs/ast/ruby/declarations.rb +291 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +762 -0
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +142 -20
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +63 -126
- data/lib/rbs/cli.rb +59 -29
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -3
- data/lib/rbs/collection/sources/git.rb +7 -0
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +121 -65
- data/lib/rbs/definition_builder/method_builder.rb +74 -33
- data/lib/rbs/definition_builder.rb +177 -20
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +410 -215
- data/lib/rbs/environment_loader.rb +2 -8
- data/lib/rbs/errors.rb +31 -21
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +568 -0
- data/lib/rbs/location_aux.rb +36 -4
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +47 -18
- data/lib/rbs/parser_aux.rb +37 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +196 -45
- data/lib/rbs/prototype/runtime.rb +12 -2
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +120 -44
- data/lib/rbs/rewriter.rb +70 -0
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +7 -4
- data/lib/rbs/test/type_check.rb +25 -3
- data/lib/rbs/type_name.rb +34 -21
- data/lib/rbs/types.rb +91 -79
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/unit_test/type_assertions.rb +44 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/runtime.rb +196 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +25 -2
- data/lib/rbs_jars.rb +39 -0
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +8 -3
- data/rbs.gemspec +37 -5
- data/schema/typeParam.json +17 -1
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +13 -10
- data/sig/ast/ruby/annotations.rbs +470 -0
- data/sig/ast/ruby/comment_block.rbs +127 -0
- data/sig/ast/ruby/declarations.rbs +158 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +198 -0
- data/sig/buffer.rbs +81 -5
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/collection/config/lockfile_generator.rbs +2 -0
- data/sig/definition.rbs +6 -0
- data/sig/definition_builder.rbs +3 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +94 -87
- data/sig/errors.rbs +26 -20
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +126 -0
- data/sig/location.rbs +32 -7
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -2
- data/sig/method_builder.rbs +9 -4
- data/sig/namespace.rbs +20 -5
- data/sig/parser.rbs +77 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/prototype/rbi.rbs +33 -4
- data/sig/resolver/type_name_resolver.rbs +36 -10
- data/sig/rewriter.rbs +45 -0
- data/sig/source.rbs +48 -0
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +15 -5
- data/sig/types.rbs +10 -8
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +15 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/src/ast.c +1628 -0
- data/src/lexer.c +3221 -0
- data/src/lexer.re +155 -0
- data/src/lexstate.c +221 -0
- data/src/location.c +31 -0
- data/src/parser.c +4258 -0
- data/src/serialize.c +958 -0
- data/src/string.c +41 -0
- data/src/util/rbs_allocator.c +171 -0
- data/src/util/rbs_assert.c +19 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +18 -92
- data/src/util/rbs_encoding.c +21308 -0
- data/src/util/rbs_unescape.c +167 -0
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +11 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +117 -1
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +73 -54
- data/stdlib/fileutils/0/fileutils.rbs +179 -160
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
- data/stdlib/json/0/json.rbs +232 -185
- data/stdlib/monitor/0/monitor.rbs +5 -5
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +521 -397
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +4 -3
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +7 -5
- data/stdlib/rdoc/0/store.rbs +2 -2
- data/stdlib/resolv/0/resolv.rbs +26 -69
- data/stdlib/ripper/0/ripper.rbs +25 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +3 -3
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -9
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1209 -95
- data/stdlib/strscan/0/string_scanner.rbs +101 -80
- data/stdlib/tempfile/0/manifest.yaml +3 -0
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +58 -7
- data/stdlib/tsort/0/cyclic.rbs +4 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +16 -15
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +21 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +8 -8
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/wasm/README.md +60 -0
- data/wasm/rbs_wasm.c +423 -0
- metadata +131 -19
- data/ext/rbs_extension/lexer.c +0 -2728
- data/ext/rbs_extension/lexer.h +0 -179
- data/ext/rbs_extension/lexer.re +0 -147
- data/ext/rbs_extension/lexstate.c +0 -175
- data/ext/rbs_extension/location.c +0 -325
- data/ext/rbs_extension/location.h +0 -85
- data/ext/rbs_extension/parser.c +0 -2982
- data/ext/rbs_extension/parser.h +0 -18
- data/ext/rbs_extension/parserstate.c +0 -411
- data/ext/rbs_extension/parserstate.h +0 -163
- data/ext/rbs_extension/unescape.c +0 -32
- data/include/rbs/ruby_objs.h +0 -72
- data/src/constants.c +0 -153
- data/src/ruby_objs.c +0 -799
data/stdlib/json/0/json.rbs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
interface _ToJson
|
|
2
|
-
def to_json: (?JSON::State state) -> String
|
|
2
|
+
def to_json: (?JSON::State? state) -> String
|
|
3
3
|
end
|
|
4
4
|
|
|
5
5
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
|
@@ -14,9 +14,6 @@ end
|
|
|
14
14
|
class JSON::GeneratorError < JSON::JSONError
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
class JSON::UnparserError < JSON::GeneratorError
|
|
18
|
-
end
|
|
19
|
-
|
|
20
17
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
|
21
18
|
# This exception is raised if a parser error occurs.
|
|
22
19
|
#
|
|
@@ -82,8 +79,8 @@ end
|
|
|
82
79
|
# JSON is a lightweight data-interchange format.
|
|
83
80
|
#
|
|
84
81
|
# A JSON value is one of the following:
|
|
85
|
-
# * Double-quoted text:
|
|
86
|
-
# * Number: `1`,
|
|
82
|
+
# * Double-quoted text: <code>"foo"</code>.
|
|
83
|
+
# * Number: `1`, <code>1.0</code>, <code>2.0e2</code>.
|
|
87
84
|
# * Boolean: `true`, `false`.
|
|
88
85
|
# * Null: `null`.
|
|
89
86
|
# * Array: an ordered list of values, enclosed by square brackets:
|
|
@@ -108,8 +105,8 @@ end
|
|
|
108
105
|
# ### Parsing JSON
|
|
109
106
|
#
|
|
110
107
|
# You can parse a String containing JSON data using either of two methods:
|
|
111
|
-
# *
|
|
112
|
-
# *
|
|
108
|
+
# * <code>JSON.parse(source, opts)</code>
|
|
109
|
+
# * <code>JSON.parse!(source, opts)</code>
|
|
113
110
|
#
|
|
114
111
|
# where
|
|
115
112
|
# * `source` is a Ruby object.
|
|
@@ -202,6 +199,24 @@ end
|
|
|
202
199
|
#
|
|
203
200
|
# ---
|
|
204
201
|
#
|
|
202
|
+
# Option `allow_duplicate_key` specifies whether duplicate keys in objects
|
|
203
|
+
# should be ignored or cause an error to be raised:
|
|
204
|
+
#
|
|
205
|
+
# When not specified:
|
|
206
|
+
# # The last value is used and a deprecation warning emitted.
|
|
207
|
+
# JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
|
|
208
|
+
# # warning: detected duplicate keys in JSON object.
|
|
209
|
+
# # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
|
|
210
|
+
#
|
|
211
|
+
# When set to ``true``
|
|
212
|
+
# # The last value is used.
|
|
213
|
+
# JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
|
|
214
|
+
#
|
|
215
|
+
# When set to ``false``, the future default:
|
|
216
|
+
# JSON.parse('{"a": 1, "a":2}') => duplicate key at line 1 column 1 (JSON::ParserError)
|
|
217
|
+
#
|
|
218
|
+
# ---
|
|
219
|
+
#
|
|
205
220
|
# Option `allow_nan` (boolean) specifies whether to allow NaN, Infinity, and
|
|
206
221
|
# MinusInfinity in `source`; defaults to `false`.
|
|
207
222
|
#
|
|
@@ -218,8 +233,22 @@ end
|
|
|
218
233
|
# ruby = JSON.parse(source, {allow_nan: true})
|
|
219
234
|
# ruby # => [NaN, Infinity, -Infinity]
|
|
220
235
|
#
|
|
236
|
+
# ---
|
|
237
|
+
#
|
|
238
|
+
# Option `allow_trailing_comma` (boolean) specifies whether to allow trailing
|
|
239
|
+
# commas in objects and arrays; defaults to `false`.
|
|
240
|
+
#
|
|
241
|
+
# With the default, `false`:
|
|
242
|
+
# JSON.parse('[1,]') # unexpected character: ']' at line 1 column 4 (JSON::ParserError)
|
|
243
|
+
#
|
|
244
|
+
# When enabled:
|
|
245
|
+
# JSON.parse('[1,]', allow_trailing_comma: true) # => [1]
|
|
246
|
+
#
|
|
221
247
|
# ###### Output Options
|
|
222
248
|
#
|
|
249
|
+
# Option `freeze` (boolean) specifies whether the returned objects will be
|
|
250
|
+
# frozen; defaults to `false`.
|
|
251
|
+
#
|
|
223
252
|
# Option `symbolize_names` (boolean) specifies whether returned Hash keys should
|
|
224
253
|
# be Symbols; defaults to `false` (use Strings).
|
|
225
254
|
#
|
|
@@ -263,12 +292,12 @@ end
|
|
|
263
292
|
# ---
|
|
264
293
|
#
|
|
265
294
|
# Option `create_additions` (boolean) specifies whether to use JSON additions in
|
|
266
|
-
# parsing. See [
|
|
295
|
+
# parsing. See [JSON Additions](#module-JSON-label-JSON+Additions).
|
|
267
296
|
#
|
|
268
297
|
# ### Generating JSON
|
|
269
298
|
#
|
|
270
299
|
# To generate a Ruby String containing JSON data, use method
|
|
271
|
-
#
|
|
300
|
+
# <code>JSON.generate(source, opts)</code>, where
|
|
272
301
|
# * `source` is a Ruby object.
|
|
273
302
|
# * `opts` is a Hash object containing options that control both input allowed
|
|
274
303
|
# and output formatting.
|
|
@@ -332,7 +361,7 @@ end
|
|
|
332
361
|
# ###### Input Options
|
|
333
362
|
#
|
|
334
363
|
# Option `allow_nan` (boolean) specifies whether `NaN`, `Infinity`, and
|
|
335
|
-
#
|
|
364
|
+
# <code>-Infinity</code> may be generated; defaults to `false`.
|
|
336
365
|
#
|
|
337
366
|
# With the default, `false`:
|
|
338
367
|
# # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
|
|
@@ -348,6 +377,25 @@ end
|
|
|
348
377
|
#
|
|
349
378
|
# ---
|
|
350
379
|
#
|
|
380
|
+
# Option `allow_duplicate_key` (boolean) specifies whether hashes with duplicate
|
|
381
|
+
# keys should be allowed or produce an error. defaults to emit a deprecation
|
|
382
|
+
# warning.
|
|
383
|
+
#
|
|
384
|
+
# With the default, (not set):
|
|
385
|
+
# Warning[:deprecated] = true
|
|
386
|
+
# JSON.generate({ foo: 1, "foo" => 2 })
|
|
387
|
+
# # warning: detected duplicate key "foo" in {foo: 1, "foo" => 2}.
|
|
388
|
+
# # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
|
|
389
|
+
# # => '{"foo":1,"foo":2}'
|
|
390
|
+
#
|
|
391
|
+
# With `false`
|
|
392
|
+
# JSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: false)
|
|
393
|
+
# # detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
|
|
394
|
+
#
|
|
395
|
+
# In version 3.0, `false` will become the default.
|
|
396
|
+
#
|
|
397
|
+
# ---
|
|
398
|
+
#
|
|
351
399
|
# Option `max_nesting` (Integer) specifies the maximum nesting depth in `obj`;
|
|
352
400
|
# defaults to `100`.
|
|
353
401
|
#
|
|
@@ -361,9 +409,9 @@ end
|
|
|
361
409
|
#
|
|
362
410
|
# ###### Escaping Options
|
|
363
411
|
#
|
|
364
|
-
# Options `script_safe` (boolean) specifies wether
|
|
365
|
-
#
|
|
366
|
-
# script tags.
|
|
412
|
+
# Options `script_safe` (boolean) specifies wether <code>'\u2028'</code>,
|
|
413
|
+
# <code>'\u2029'</code> and <code>'/'</code> should be escaped as to make the
|
|
414
|
+
# JSON object safe to interpolate in script tags.
|
|
367
415
|
#
|
|
368
416
|
# Options `ascii_only` (boolean) specifies wether all characters outside the
|
|
369
417
|
# ASCII range should be escaped.
|
|
@@ -377,19 +425,21 @@ end
|
|
|
377
425
|
# format, using whitespace. See also JSON.pretty_generate.
|
|
378
426
|
#
|
|
379
427
|
# * Option `array_nl` (String) specifies a string (usually a newline) to be
|
|
380
|
-
# inserted after each JSON array; defaults to the empty String,
|
|
428
|
+
# inserted after each JSON array; defaults to the empty String,
|
|
429
|
+
# <code>''</code>.
|
|
381
430
|
# * Option `object_nl` (String) specifies a string (usually a newline) to be
|
|
382
|
-
# inserted after each JSON object; defaults to the empty String,
|
|
431
|
+
# inserted after each JSON object; defaults to the empty String,
|
|
432
|
+
# <code>''</code>.
|
|
383
433
|
# * Option `indent` (String) specifies the string (usually spaces) to be used
|
|
384
|
-
# for indentation; defaults to the empty String,
|
|
385
|
-
# String,
|
|
386
|
-
# specify newlines.
|
|
434
|
+
# for indentation; defaults to the empty String, <code>''</code>; defaults
|
|
435
|
+
# to the empty String, <code>''</code>; has no effect unless options
|
|
436
|
+
# `array_nl` or `object_nl` specify newlines.
|
|
387
437
|
# * Option `space` (String) specifies a string (usually a space) to be
|
|
388
438
|
# inserted after the colon in each JSON object's pair; defaults to the empty
|
|
389
|
-
# String,
|
|
439
|
+
# String, <code>''</code>.
|
|
390
440
|
# * Option `space_before` (String) specifies a string (usually a space) to be
|
|
391
441
|
# inserted before the colon in each JSON object's pair; defaults to the
|
|
392
|
-
# empty String,
|
|
442
|
+
# empty String, <code>''</code>.
|
|
393
443
|
#
|
|
394
444
|
# In this example, `obj` is used first to generate the shortest JSON data (no
|
|
395
445
|
# whitespace), then again with all formatting options specified:
|
|
@@ -423,6 +473,9 @@ end
|
|
|
423
473
|
#
|
|
424
474
|
# ## JSON Additions
|
|
425
475
|
#
|
|
476
|
+
# Note that JSON Additions must only be used with trusted data, and is
|
|
477
|
+
# deprecated.
|
|
478
|
+
#
|
|
426
479
|
# When you "round trip" a non-String object from Ruby to JSON and back, you have
|
|
427
480
|
# a new String, instead of the object you began with:
|
|
428
481
|
# ruby0 = Range.new(0, 2)
|
|
@@ -468,26 +521,26 @@ end
|
|
|
468
521
|
# With addition: 0..2 (Range)
|
|
469
522
|
#
|
|
470
523
|
# The JSON module includes additions for certain classes. You can also craft
|
|
471
|
-
# custom additions. See [Custom
|
|
524
|
+
# custom additions. See [Custom JSON
|
|
472
525
|
# Additions](#module-JSON-label-Custom+JSON+Additions).
|
|
473
526
|
#
|
|
474
527
|
# ### Built-in Additions
|
|
475
528
|
#
|
|
476
529
|
# The JSON module includes additions for certain classes. To use an addition,
|
|
477
530
|
# `require` its source:
|
|
478
|
-
# * BigDecimal:
|
|
479
|
-
# * Complex:
|
|
480
|
-
# * Date:
|
|
481
|
-
# * DateTime:
|
|
482
|
-
# * Exception:
|
|
483
|
-
# * OpenStruct:
|
|
484
|
-
# * Range:
|
|
485
|
-
# * Rational:
|
|
486
|
-
# * Regexp:
|
|
487
|
-
# * Set:
|
|
488
|
-
# * Struct:
|
|
489
|
-
# * Symbol:
|
|
490
|
-
# * Time:
|
|
531
|
+
# * BigDecimal: <code>require 'json/add/bigdecimal'</code>
|
|
532
|
+
# * Complex: <code>require 'json/add/complex'</code>
|
|
533
|
+
# * Date: <code>require 'json/add/date'</code>
|
|
534
|
+
# * DateTime: <code>require 'json/add/date_time'</code>
|
|
535
|
+
# * Exception: <code>require 'json/add/exception'</code>
|
|
536
|
+
# * OpenStruct: <code>require 'json/add/ostruct'</code>
|
|
537
|
+
# * Range: <code>require 'json/add/range'</code>
|
|
538
|
+
# * Rational: <code>require 'json/add/rational'</code>
|
|
539
|
+
# * Regexp: <code>require 'json/add/regexp'</code>
|
|
540
|
+
# * Set: <code>require 'json/add/set'</code>
|
|
541
|
+
# * Struct: <code>require 'json/add/struct'</code>
|
|
542
|
+
# * Symbol: <code>require 'json/add/symbol'</code>
|
|
543
|
+
# * Time: <code>require 'json/add/time'</code>
|
|
491
544
|
#
|
|
492
545
|
# To reduce punctuation clutter, the examples below show the generated JSON via
|
|
493
546
|
# `puts`, rather than the usual `inspect`,
|
|
@@ -711,8 +764,6 @@ module JSON
|
|
|
711
764
|
#
|
|
712
765
|
def self.create_id=: (_ToS create_id) -> _ToS
|
|
713
766
|
|
|
714
|
-
def self.deep_const_get: (interned path) -> untyped
|
|
715
|
-
|
|
716
767
|
# <!--
|
|
717
768
|
# rdoc-file=ext/json/lib/json/common.rb
|
|
718
769
|
# - JSON.dump(obj, io = nil, limit = nil)
|
|
@@ -754,6 +805,7 @@ module JSON
|
|
|
754
805
|
# opts = JSON.dump_default_options
|
|
755
806
|
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
|
756
807
|
#
|
|
808
|
+
%a{deprecated}
|
|
757
809
|
def self.dump_default_options: () -> options
|
|
758
810
|
|
|
759
811
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
|
@@ -761,6 +813,7 @@ module JSON
|
|
|
761
813
|
# opts = JSON.dump_default_options
|
|
762
814
|
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
|
763
815
|
#
|
|
816
|
+
%a{deprecated}
|
|
764
817
|
def self.dump_default_options=: (options) -> options
|
|
765
818
|
|
|
766
819
|
# <!--
|
|
@@ -778,19 +831,16 @@ module JSON
|
|
|
778
831
|
# # Raises SystemStackError (stack level too deep):
|
|
779
832
|
# JSON.fast_generate(a)
|
|
780
833
|
#
|
|
834
|
+
%a{deprecated}
|
|
781
835
|
def self?.fast_generate: (_ToJson obj, ?options opts) -> String
|
|
782
836
|
|
|
783
|
-
alias self.fast_unparse self.fast_generate
|
|
784
|
-
|
|
785
|
-
alias fast_unparse fast_generate
|
|
786
|
-
|
|
787
837
|
# <!--
|
|
788
838
|
# rdoc-file=ext/json/lib/json/common.rb
|
|
789
839
|
# - JSON.generate(obj, opts = nil) -> new_string
|
|
790
840
|
# -->
|
|
791
841
|
# Returns a String containing the generated JSON data.
|
|
792
842
|
#
|
|
793
|
-
# See also JSON.
|
|
843
|
+
# See also JSON.pretty_generate.
|
|
794
844
|
#
|
|
795
845
|
# Argument `obj` is the Ruby object to be converted to JSON.
|
|
796
846
|
#
|
|
@@ -809,7 +859,7 @@ module JSON
|
|
|
809
859
|
# json = JSON.generate(obj)
|
|
810
860
|
# json # => '{"foo":0,"bar":"s","baz":"bat"}'
|
|
811
861
|
#
|
|
812
|
-
# For examples of generating from other Ruby objects, see [Generating
|
|
862
|
+
# For examples of generating from other Ruby objects, see [Generating JSON from
|
|
813
863
|
# Other Objects](#module-JSON-label-Generating+JSON+from+Other+Objects).
|
|
814
864
|
#
|
|
815
865
|
# ---
|
|
@@ -832,14 +882,7 @@ module JSON
|
|
|
832
882
|
|
|
833
883
|
# <!--
|
|
834
884
|
# rdoc-file=ext/json/lib/json/common.rb
|
|
835
|
-
# -
|
|
836
|
-
# -->
|
|
837
|
-
# Encodes string using String.encode.
|
|
838
|
-
#
|
|
839
|
-
def self.iconv: (encoding to, encoding from, String string) -> String
|
|
840
|
-
|
|
841
|
-
# <!--
|
|
842
|
-
# rdoc-file=ext/json/lib/json/common.rb
|
|
885
|
+
# - JSON.load(source, options = {}) -> object
|
|
843
886
|
# - JSON.load(source, proc = nil, options = {}) -> object
|
|
844
887
|
# -->
|
|
845
888
|
# Returns the Ruby objects created by parsing the given `source`.
|
|
@@ -854,15 +897,17 @@ module JSON
|
|
|
854
897
|
# in JSON version 3.0, `load` will have `create_additions` disabled by default.
|
|
855
898
|
#
|
|
856
899
|
# * Argument `source` must be, or be convertible to, a String:
|
|
857
|
-
# * If `source` responds to instance method `to_str`,
|
|
858
|
-
# becomes the source.
|
|
859
|
-
# * If `source` responds to instance method `to_io`,
|
|
860
|
-
# becomes the source.
|
|
861
|
-
# * If `source` responds to instance method `read`,
|
|
862
|
-
# the source.
|
|
863
|
-
# * If both of the following are true, source becomes the String
|
|
900
|
+
# * If `source` responds to instance method `to_str`,
|
|
901
|
+
# <code>source.to_str</code> becomes the source.
|
|
902
|
+
# * If `source` responds to instance method `to_io`,
|
|
903
|
+
# <code>source.to_io.read</code> becomes the source.
|
|
904
|
+
# * If `source` responds to instance method `read`,
|
|
905
|
+
# <code>source.read</code> becomes the source.
|
|
906
|
+
# * If both of the following are true, source becomes the String
|
|
907
|
+
# <code>'null'</code>:
|
|
864
908
|
# * Option `allow_blank` specifies a truthy value.
|
|
865
|
-
# * The source, as defined above, is `nil` or the empty String
|
|
909
|
+
# * The source, as defined above, is `nil` or the empty String
|
|
910
|
+
# <code>''</code>.
|
|
866
911
|
# * Otherwise, `source` remains the source.
|
|
867
912
|
# * Argument `proc`, if given, must be a Proc that accepts one argument. It
|
|
868
913
|
# will be called recursively with each result (depth-first order). See
|
|
@@ -874,7 +919,7 @@ module JSON
|
|
|
874
919
|
# ---
|
|
875
920
|
#
|
|
876
921
|
# When no `proc` is given, modifies `source` as above and returns the result of
|
|
877
|
-
#
|
|
922
|
+
# <code>parse(source, opts)</code>; see #parse.
|
|
878
923
|
#
|
|
879
924
|
# Source for following examples:
|
|
880
925
|
# source = <<~JSON
|
|
@@ -909,8 +954,8 @@ module JSON
|
|
|
909
954
|
#
|
|
910
955
|
# When `proc` is given:
|
|
911
956
|
# * Modifies `source` as above.
|
|
912
|
-
# * Gets the `result` from calling
|
|
913
|
-
# * Recursively calls
|
|
957
|
+
# * Gets the `result` from calling <code>parse(source, opts)</code>.
|
|
958
|
+
# * Recursively calls <code>proc(result)</code>.
|
|
914
959
|
# * Returns the final result.
|
|
915
960
|
#
|
|
916
961
|
# Example:
|
|
@@ -952,6 +997,7 @@ module JSON
|
|
|
952
997
|
# when Array
|
|
953
998
|
# obj.map! {|v| deserialize_obj v }
|
|
954
999
|
# end
|
|
1000
|
+
# obj
|
|
955
1001
|
# })
|
|
956
1002
|
# pp ruby
|
|
957
1003
|
#
|
|
@@ -974,7 +1020,8 @@ module JSON
|
|
|
974
1020
|
# #<Admin:0x00000000064c41f8
|
|
975
1021
|
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
|
|
976
1022
|
#
|
|
977
|
-
def self?.load: (string | _ReadableIO | _Read source, ?
|
|
1023
|
+
def self?.load: (string | _ReadableIO | _Read source, ?options options) -> untyped
|
|
1024
|
+
| [T] (string | _ReadableIO | _Read source, ^(?) -> T, ?options options) -> T
|
|
978
1025
|
|
|
979
1026
|
# <!--
|
|
980
1027
|
# rdoc-file=ext/json/lib/json/common.rb
|
|
@@ -1003,6 +1050,7 @@ module JSON
|
|
|
1003
1050
|
# opts = JSON.load_default_options
|
|
1004
1051
|
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
|
1005
1052
|
#
|
|
1053
|
+
%a{deprecated}
|
|
1006
1054
|
def self.load_default_options: () -> options
|
|
1007
1055
|
|
|
1008
1056
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
|
@@ -1010,6 +1058,7 @@ module JSON
|
|
|
1010
1058
|
# opts = JSON.load_default_options
|
|
1011
1059
|
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
|
1012
1060
|
#
|
|
1061
|
+
%a{deprecated}
|
|
1013
1062
|
def self.load_default_options=: (options) -> options
|
|
1014
1063
|
|
|
1015
1064
|
# <!--
|
|
@@ -1038,7 +1087,7 @@ module JSON
|
|
|
1038
1087
|
# ruby.class # => Hash
|
|
1039
1088
|
#
|
|
1040
1089
|
# For examples of parsing for all JSON data types, see [Parsing
|
|
1041
|
-
#
|
|
1090
|
+
# JSON](#module-JSON-label-Parsing+JSON).
|
|
1042
1091
|
#
|
|
1043
1092
|
# Parses nested JSON objects:
|
|
1044
1093
|
# source = <<~JSON
|
|
@@ -1120,29 +1169,6 @@ module JSON
|
|
|
1120
1169
|
#
|
|
1121
1170
|
def self?.pretty_generate: (_ToJson obj, ?options opts) -> untyped
|
|
1122
1171
|
|
|
1123
|
-
alias self.pretty_unparse self.pretty_generate
|
|
1124
|
-
|
|
1125
|
-
alias pretty_unparse pretty_generate
|
|
1126
|
-
|
|
1127
|
-
# Recursively calls passed *Proc* if the parsed data structure is an *Array* or
|
|
1128
|
-
# *Hash*
|
|
1129
|
-
#
|
|
1130
|
-
def self?.recurse_proc: (untyped result) { (*untyped) -> void } -> void
|
|
1131
|
-
|
|
1132
|
-
# <!--
|
|
1133
|
-
# rdoc-file=ext/json/lib/json/common.rb
|
|
1134
|
-
# - restore(source, proc = nil, options = nil)
|
|
1135
|
-
# -->
|
|
1136
|
-
#
|
|
1137
|
-
alias self.restore self.load
|
|
1138
|
-
|
|
1139
|
-
# <!--
|
|
1140
|
-
# rdoc-file=ext/json/lib/json/common.rb
|
|
1141
|
-
# - restore(source, proc = nil, options = nil)
|
|
1142
|
-
# -->
|
|
1143
|
-
#
|
|
1144
|
-
alias restore load
|
|
1145
|
-
|
|
1146
1172
|
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
|
1147
1173
|
# Sets or Returns the JSON generator state class that is used by JSON.
|
|
1148
1174
|
#
|
|
@@ -1152,10 +1178,6 @@ module JSON
|
|
|
1152
1178
|
# Sets or Returns the JSON generator state class that is used by JSON.
|
|
1153
1179
|
#
|
|
1154
1180
|
def self.state=: (state) -> state
|
|
1155
|
-
|
|
1156
|
-
alias self.unparse self.generate
|
|
1157
|
-
|
|
1158
|
-
alias unparse generate
|
|
1159
1181
|
end
|
|
1160
1182
|
|
|
1161
1183
|
JSON::FAST_STATE_PROTOTYPE: JSON::state
|
|
@@ -1193,6 +1215,7 @@ module Kernel
|
|
|
1193
1215
|
# Outputs *objs* to STDOUT as JSON strings in the shortest form, that is in one
|
|
1194
1216
|
# line.
|
|
1195
1217
|
#
|
|
1218
|
+
%a{deprecated}
|
|
1196
1219
|
def j: (*_ToJson) -> nil
|
|
1197
1220
|
|
|
1198
1221
|
# <!--
|
|
@@ -1202,11 +1225,12 @@ module Kernel
|
|
|
1202
1225
|
# Outputs *objs* to STDOUT as JSON strings in a pretty format, with indentation
|
|
1203
1226
|
# and over many lines.
|
|
1204
1227
|
#
|
|
1228
|
+
%a{deprecated}
|
|
1205
1229
|
def jj: (*_ToJson) -> nil
|
|
1206
1230
|
|
|
1207
1231
|
# <!--
|
|
1208
1232
|
# rdoc-file=ext/json/lib/json/common.rb
|
|
1209
|
-
# - JSON(object,
|
|
1233
|
+
# - JSON(object, opts = nil)
|
|
1210
1234
|
# -->
|
|
1211
1235
|
# If *object* is string-like, parse the string and return the parsed result as a
|
|
1212
1236
|
# Ruby data structure. Otherwise, generate a JSON text from the Ruby data
|
|
@@ -1225,28 +1249,28 @@ class Object
|
|
|
1225
1249
|
# it to a JSON string, and returns the result. This is a fallback, if no
|
|
1226
1250
|
# special method #to_json was defined for some object.
|
|
1227
1251
|
#
|
|
1228
|
-
def to_json: (?JSON::State state) -> String
|
|
1252
|
+
def to_json: (?JSON::State? state) -> String
|
|
1229
1253
|
end
|
|
1230
1254
|
|
|
1231
1255
|
%a{annotate:rdoc:skip}
|
|
1232
1256
|
class NilClass
|
|
1233
1257
|
# Returns a JSON string for nil: 'null'.
|
|
1234
1258
|
#
|
|
1235
|
-
def to_json: (?JSON::State state) -> String
|
|
1259
|
+
def to_json: (?JSON::State? state) -> String
|
|
1236
1260
|
end
|
|
1237
1261
|
|
|
1238
1262
|
%a{annotate:rdoc:skip}
|
|
1239
1263
|
class TrueClass
|
|
1240
1264
|
# Returns a JSON string for true: 'true'.
|
|
1241
1265
|
#
|
|
1242
|
-
def to_json: (?JSON::State state) -> String
|
|
1266
|
+
def to_json: (?JSON::State? state) -> String
|
|
1243
1267
|
end
|
|
1244
1268
|
|
|
1245
1269
|
%a{annotate:rdoc:skip}
|
|
1246
1270
|
class FalseClass
|
|
1247
1271
|
# Returns a JSON string for false: 'false'.
|
|
1248
1272
|
#
|
|
1249
|
-
def to_json: (?JSON::State state) -> String
|
|
1273
|
+
def to_json: (?JSON::State? state) -> String
|
|
1250
1274
|
end
|
|
1251
1275
|
|
|
1252
1276
|
%a{annotate:rdoc:skip}
|
|
@@ -1255,21 +1279,21 @@ class String
|
|
|
1255
1279
|
# returns a JSON string encoded with UTF16 big endian characters as
|
|
1256
1280
|
# \u????.
|
|
1257
1281
|
#
|
|
1258
|
-
def to_json: (?JSON::State state) -> String
|
|
1282
|
+
def to_json: (?JSON::State? state) -> String
|
|
1259
1283
|
end
|
|
1260
1284
|
|
|
1261
1285
|
%a{annotate:rdoc:skip}
|
|
1262
1286
|
class Integer
|
|
1263
1287
|
# Returns a JSON string representation for this Integer number.
|
|
1264
1288
|
#
|
|
1265
|
-
def to_json: (?JSON::State state) -> String
|
|
1289
|
+
def to_json: (?JSON::State? state) -> String
|
|
1266
1290
|
end
|
|
1267
1291
|
|
|
1268
1292
|
%a{annotate:rdoc:skip}
|
|
1269
1293
|
class Float
|
|
1270
1294
|
# Returns a JSON string representation for this Float number.
|
|
1271
1295
|
#
|
|
1272
|
-
def to_json: (?JSON::State state) -> String
|
|
1296
|
+
def to_json: (?JSON::State? state) -> String
|
|
1273
1297
|
end
|
|
1274
1298
|
|
|
1275
1299
|
%a{annotate:rdoc:skip}
|
|
@@ -1279,17 +1303,17 @@ class Hash[unchecked out K, unchecked out V]
|
|
|
1279
1303
|
# _state_ is a JSON::State object, that can also be used to configure the
|
|
1280
1304
|
# produced JSON string output further.
|
|
1281
1305
|
#
|
|
1282
|
-
def to_json: (?JSON::State state) -> String
|
|
1306
|
+
def to_json: (?JSON::State? state) -> String
|
|
1283
1307
|
end
|
|
1284
1308
|
|
|
1285
1309
|
%a{annotate:rdoc:skip}
|
|
1286
|
-
class Array[unchecked out
|
|
1310
|
+
class Array[unchecked out E]
|
|
1287
1311
|
# Returns a JSON string containing a JSON array, that is generated from
|
|
1288
1312
|
# this Array instance.
|
|
1289
1313
|
# _state_ is a JSON::State object, that can also be used to configure the
|
|
1290
1314
|
# produced JSON string output further.
|
|
1291
1315
|
#
|
|
1292
|
-
def to_json: (?JSON::State state) -> String
|
|
1316
|
+
def to_json: (?JSON::State? state) -> String
|
|
1293
1317
|
end
|
|
1294
1318
|
|
|
1295
1319
|
%a{annotate:rdoc:skip}
|
|
@@ -1306,19 +1330,20 @@ class BigDecimal
|
|
|
1306
1330
|
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
|
1307
1331
|
# - as_json(*)
|
|
1308
1332
|
# -->
|
|
1309
|
-
# Methods
|
|
1310
|
-
# serialize and deserialize a
|
|
1311
|
-
# [Marshal](rdoc-ref:Marshal).
|
|
1333
|
+
# Methods <code>BigDecimal#as_json</code> and
|
|
1334
|
+
# <code>BigDecimal.json_create</code> may be used to serialize and deserialize a
|
|
1335
|
+
# BigDecimal object; see [Marshal](rdoc-ref:Marshal).
|
|
1312
1336
|
#
|
|
1313
|
-
# Method
|
|
1314
|
-
# representing `self`:
|
|
1337
|
+
# Method <code>BigDecimal#as_json</code> serializes `self`, returning a
|
|
1338
|
+
# 2-element hash representing `self`:
|
|
1315
1339
|
#
|
|
1316
1340
|
# require 'json/add/bigdecimal'
|
|
1317
1341
|
# x = BigDecimal(2).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
|
1318
1342
|
# y = BigDecimal(2.0, 4).as_json # => {"json_class"=>"BigDecimal", "b"=>"36:0.2e1"}
|
|
1319
1343
|
# z = BigDecimal(Complex(2, 0)).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
|
1320
1344
|
#
|
|
1321
|
-
# Method
|
|
1345
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a
|
|
1346
|
+
# BigDecimal object:
|
|
1322
1347
|
#
|
|
1323
1348
|
# BigDecimal.json_create(x) # => 0.2e1
|
|
1324
1349
|
# BigDecimal.json_create(y) # => 0.2e1
|
|
@@ -1343,7 +1368,7 @@ class BigDecimal
|
|
|
1343
1368
|
# {"json_class":"BigDecimal","b":"36:0.2e1"}
|
|
1344
1369
|
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
|
1345
1370
|
#
|
|
1346
|
-
def to_json: (?JSON::State state) -> String
|
|
1371
|
+
def to_json: (?JSON::State? state) -> String
|
|
1347
1372
|
end
|
|
1348
1373
|
|
|
1349
1374
|
%a{annotate:rdoc:skip}
|
|
@@ -1360,17 +1385,19 @@ class Complex
|
|
|
1360
1385
|
# rdoc-file=ext/json/lib/json/add/complex.rb
|
|
1361
1386
|
# - as_json(*)
|
|
1362
1387
|
# -->
|
|
1363
|
-
# Methods
|
|
1364
|
-
# and deserialize a Complex object; see
|
|
1388
|
+
# Methods <code>Complex#as_json</code> and <code>Complex.json_create</code> may
|
|
1389
|
+
# be used to serialize and deserialize a Complex object; see
|
|
1390
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1365
1391
|
#
|
|
1366
|
-
# Method
|
|
1367
|
-
# representing `self`:
|
|
1392
|
+
# Method <code>Complex#as_json</code> serializes `self`, returning a 2-element
|
|
1393
|
+
# hash representing `self`:
|
|
1368
1394
|
#
|
|
1369
1395
|
# require 'json/add/complex'
|
|
1370
1396
|
# x = Complex(2).as_json # => {"json_class"=>"Complex", "r"=>2, "i"=>0}
|
|
1371
1397
|
# y = Complex(2.0, 4).as_json # => {"json_class"=>"Complex", "r"=>2.0, "i"=>4}
|
|
1372
1398
|
#
|
|
1373
|
-
# Method
|
|
1399
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Complex
|
|
1400
|
+
# object:
|
|
1374
1401
|
#
|
|
1375
1402
|
# Complex.json_create(x) # => (2+0i)
|
|
1376
1403
|
# Complex.json_create(y) # => (2.0+4i)
|
|
@@ -1392,7 +1419,7 @@ class Complex
|
|
|
1392
1419
|
# {"json_class":"Complex","r":2,"i":0}
|
|
1393
1420
|
# {"json_class":"Complex","r":2.0,"i":4}
|
|
1394
1421
|
#
|
|
1395
|
-
def to_json: (?JSON::State state) -> String
|
|
1422
|
+
def to_json: (?JSON::State? state) -> String
|
|
1396
1423
|
end
|
|
1397
1424
|
|
|
1398
1425
|
%a{annotate:rdoc:skip}
|
|
@@ -1409,17 +1436,19 @@ class Date
|
|
|
1409
1436
|
# rdoc-file=ext/json/lib/json/add/date.rb
|
|
1410
1437
|
# - as_json(*)
|
|
1411
1438
|
# -->
|
|
1412
|
-
# Methods
|
|
1413
|
-
# deserialize a Date object; see
|
|
1439
|
+
# Methods <code>Date#as_json</code> and <code>Date.json_create</code> may be
|
|
1440
|
+
# used to serialize and deserialize a Date object; see
|
|
1441
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1414
1442
|
#
|
|
1415
|
-
# Method
|
|
1443
|
+
# Method <code>Date#as_json</code> serializes `self`, returning a 2-element hash
|
|
1416
1444
|
# representing `self`:
|
|
1417
1445
|
#
|
|
1418
1446
|
# require 'json/add/date'
|
|
1419
1447
|
# x = Date.today.as_json
|
|
1420
1448
|
# # => {"json_class"=>"Date", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
|
1421
1449
|
#
|
|
1422
|
-
# Method
|
|
1450
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Date
|
|
1451
|
+
# object:
|
|
1423
1452
|
#
|
|
1424
1453
|
# Date.json_create(x)
|
|
1425
1454
|
# # => #<Date: 2023-11-21 ((2460270j,0s,0n),+0s,2299161j)>
|
|
@@ -1439,7 +1468,7 @@ class Date
|
|
|
1439
1468
|
#
|
|
1440
1469
|
# {"json_class":"Date","y":2023,"m":11,"d":21,"sg":2299161.0}
|
|
1441
1470
|
#
|
|
1442
|
-
def to_json: (?JSON::State state) -> String
|
|
1471
|
+
def to_json: (?JSON::State? state) -> String
|
|
1443
1472
|
end
|
|
1444
1473
|
|
|
1445
1474
|
%a{annotate:rdoc:skip}
|
|
@@ -1456,17 +1485,19 @@ class DateTime
|
|
|
1456
1485
|
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
|
1457
1486
|
# - as_json(*)
|
|
1458
1487
|
# -->
|
|
1459
|
-
# Methods
|
|
1460
|
-
# and deserialize a DateTime object; see
|
|
1488
|
+
# Methods <code>DateTime#as_json</code> and <code>DateTime.json_create</code>
|
|
1489
|
+
# may be used to serialize and deserialize a DateTime object; see
|
|
1490
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1461
1491
|
#
|
|
1462
|
-
# Method
|
|
1463
|
-
# representing `self`:
|
|
1492
|
+
# Method <code>DateTime#as_json</code> serializes `self`, returning a 2-element
|
|
1493
|
+
# hash representing `self`:
|
|
1464
1494
|
#
|
|
1465
1495
|
# require 'json/add/datetime'
|
|
1466
1496
|
# x = DateTime.now.as_json
|
|
1467
1497
|
# # => {"json_class"=>"DateTime", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
|
1468
1498
|
#
|
|
1469
|
-
# Method
|
|
1499
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a DateTime
|
|
1500
|
+
# object:
|
|
1470
1501
|
#
|
|
1471
1502
|
# DateTime.json_create(x) # BUG? Raises Date::Error "invalid date"
|
|
1472
1503
|
#
|
|
@@ -1485,7 +1516,7 @@ class DateTime
|
|
|
1485
1516
|
#
|
|
1486
1517
|
# {"json_class":"DateTime","y":2023,"m":11,"d":21,"sg":2299161.0}
|
|
1487
1518
|
#
|
|
1488
|
-
def to_json: (?JSON::State state) -> String
|
|
1519
|
+
def to_json: (?JSON::State? state) -> String
|
|
1489
1520
|
end
|
|
1490
1521
|
|
|
1491
1522
|
%a{annotate:rdoc:skip}
|
|
@@ -1502,16 +1533,18 @@ class Exception
|
|
|
1502
1533
|
# rdoc-file=ext/json/lib/json/add/exception.rb
|
|
1503
1534
|
# - as_json(*)
|
|
1504
1535
|
# -->
|
|
1505
|
-
# Methods
|
|
1506
|
-
# serialize and deserialize a Exception object; see
|
|
1536
|
+
# Methods <code>Exception#as_json</code> and <code>Exception.json_create</code>
|
|
1537
|
+
# may be used to serialize and deserialize a Exception object; see
|
|
1538
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1507
1539
|
#
|
|
1508
|
-
# Method
|
|
1509
|
-
# representing `self`:
|
|
1540
|
+
# Method <code>Exception#as_json</code> serializes `self`, returning a 2-element
|
|
1541
|
+
# hash representing `self`:
|
|
1510
1542
|
#
|
|
1511
1543
|
# require 'json/add/exception'
|
|
1512
1544
|
# x = Exception.new('Foo').as_json # => {"json_class"=>"Exception", "m"=>"Foo", "b"=>nil}
|
|
1513
1545
|
#
|
|
1514
|
-
# Method
|
|
1546
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a
|
|
1547
|
+
# Exception object:
|
|
1515
1548
|
#
|
|
1516
1549
|
# Exception.json_create(x) # => #<Exception: Foo>
|
|
1517
1550
|
#
|
|
@@ -1530,7 +1563,7 @@ class Exception
|
|
|
1530
1563
|
#
|
|
1531
1564
|
# {"json_class":"Exception","m":"Foo","b":null}
|
|
1532
1565
|
#
|
|
1533
|
-
def to_json: (?JSON::State state) -> String
|
|
1566
|
+
def to_json: (?JSON::State? state) -> String
|
|
1534
1567
|
end
|
|
1535
1568
|
|
|
1536
1569
|
%a{annotate:rdoc:skip}
|
|
@@ -1547,18 +1580,19 @@ class OpenStruct
|
|
|
1547
1580
|
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
|
1548
1581
|
# - as_json(*)
|
|
1549
1582
|
# -->
|
|
1550
|
-
# Methods
|
|
1551
|
-
# serialize and deserialize a
|
|
1552
|
-
# [Marshal](rdoc-ref:Marshal).
|
|
1583
|
+
# Methods <code>OpenStruct#as_json</code> and
|
|
1584
|
+
# <code>OpenStruct.json_create</code> may be used to serialize and deserialize a
|
|
1585
|
+
# OpenStruct object; see [Marshal](rdoc-ref:Marshal).
|
|
1553
1586
|
#
|
|
1554
|
-
# Method
|
|
1555
|
-
# representing `self`:
|
|
1587
|
+
# Method <code>OpenStruct#as_json</code> serializes `self`, returning a
|
|
1588
|
+
# 2-element hash representing `self`:
|
|
1556
1589
|
#
|
|
1557
1590
|
# require 'json/add/ostruct'
|
|
1558
1591
|
# x = OpenStruct.new('name' => 'Rowdy', :age => nil).as_json
|
|
1559
1592
|
# # => {"json_class"=>"OpenStruct", "t"=>{:name=>'Rowdy', :age=>nil}}
|
|
1560
1593
|
#
|
|
1561
|
-
# Method
|
|
1594
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a
|
|
1595
|
+
# OpenStruct object:
|
|
1562
1596
|
#
|
|
1563
1597
|
# OpenStruct.json_create(x)
|
|
1564
1598
|
# # => #<OpenStruct name='Rowdy', age=nil>
|
|
@@ -1578,11 +1612,11 @@ class OpenStruct
|
|
|
1578
1612
|
#
|
|
1579
1613
|
# {"json_class":"OpenStruct","t":{'name':'Rowdy',"age":null}}
|
|
1580
1614
|
#
|
|
1581
|
-
def to_json: (?JSON::State state) -> String
|
|
1615
|
+
def to_json: (?JSON::State? state) -> String
|
|
1582
1616
|
end
|
|
1583
1617
|
|
|
1584
1618
|
%a{annotate:rdoc:skip}
|
|
1585
|
-
class Range[out
|
|
1619
|
+
class Range[out E]
|
|
1586
1620
|
# <!--
|
|
1587
1621
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
|
1588
1622
|
# - json_create(object)
|
|
@@ -1595,24 +1629,26 @@ class Range[out Elem]
|
|
|
1595
1629
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
|
1596
1630
|
# - as_json(*)
|
|
1597
1631
|
# -->
|
|
1598
|
-
# Methods
|
|
1599
|
-
# deserialize a Range object; see
|
|
1632
|
+
# Methods <code>Range#as_json</code> and <code>Range.json_create</code> may be
|
|
1633
|
+
# used to serialize and deserialize a Range object; see
|
|
1634
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1600
1635
|
#
|
|
1601
|
-
# Method
|
|
1602
|
-
# representing `self`:
|
|
1636
|
+
# Method <code>Range#as_json</code> serializes `self`, returning a 2-element
|
|
1637
|
+
# hash representing `self`:
|
|
1603
1638
|
#
|
|
1604
1639
|
# require 'json/add/range'
|
|
1605
1640
|
# x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
|
1606
1641
|
# y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
|
1607
1642
|
# z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
|
1608
1643
|
#
|
|
1609
|
-
# Method
|
|
1644
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Range
|
|
1645
|
+
# object:
|
|
1610
1646
|
#
|
|
1611
1647
|
# Range.json_create(x) # => 1..4
|
|
1612
1648
|
# Range.json_create(y) # => 1...4
|
|
1613
1649
|
# Range.json_create(z) # => "a".."d"
|
|
1614
1650
|
#
|
|
1615
|
-
def as_json: (*untyped) -> Hash[String, String | [
|
|
1651
|
+
def as_json: (*untyped) -> Hash[String, String | [ E, E, bool ]]
|
|
1616
1652
|
|
|
1617
1653
|
# <!--
|
|
1618
1654
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
|
@@ -1631,7 +1667,7 @@ class Range[out Elem]
|
|
|
1631
1667
|
# {"json_class":"Range","a":[1,4,true]}
|
|
1632
1668
|
# {"json_class":"Range","a":["a","d",false]}
|
|
1633
1669
|
#
|
|
1634
|
-
def to_json: (?JSON::State state) -> String
|
|
1670
|
+
def to_json: (?JSON::State? state) -> String
|
|
1635
1671
|
end
|
|
1636
1672
|
|
|
1637
1673
|
%a{annotate:rdoc:skip}
|
|
@@ -1648,17 +1684,19 @@ class Rational
|
|
|
1648
1684
|
# rdoc-file=ext/json/lib/json/add/rational.rb
|
|
1649
1685
|
# - as_json(*)
|
|
1650
1686
|
# -->
|
|
1651
|
-
# Methods
|
|
1652
|
-
# and deserialize a Rational object; see
|
|
1687
|
+
# Methods <code>Rational#as_json</code> and <code>Rational.json_create</code>
|
|
1688
|
+
# may be used to serialize and deserialize a Rational object; see
|
|
1689
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1653
1690
|
#
|
|
1654
|
-
# Method
|
|
1655
|
-
# representing `self`:
|
|
1691
|
+
# Method <code>Rational#as_json</code> serializes `self`, returning a 2-element
|
|
1692
|
+
# hash representing `self`:
|
|
1656
1693
|
#
|
|
1657
1694
|
# require 'json/add/rational'
|
|
1658
1695
|
# x = Rational(2, 3).as_json
|
|
1659
1696
|
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
|
1660
1697
|
#
|
|
1661
|
-
# Method
|
|
1698
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Rational
|
|
1699
|
+
# object:
|
|
1662
1700
|
#
|
|
1663
1701
|
# Rational.json_create(x)
|
|
1664
1702
|
# # => (2/3)
|
|
@@ -1678,7 +1716,7 @@ class Rational
|
|
|
1678
1716
|
#
|
|
1679
1717
|
# {"json_class":"Rational","n":2,"d":3}
|
|
1680
1718
|
#
|
|
1681
|
-
def to_json: (?JSON::State state) -> String
|
|
1719
|
+
def to_json: (?JSON::State? state) -> String
|
|
1682
1720
|
end
|
|
1683
1721
|
|
|
1684
1722
|
%a{annotate:rdoc:skip}
|
|
@@ -1695,17 +1733,19 @@ class Regexp
|
|
|
1695
1733
|
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
|
1696
1734
|
# - as_json(*)
|
|
1697
1735
|
# -->
|
|
1698
|
-
# Methods
|
|
1699
|
-
# deserialize a Regexp object; see
|
|
1736
|
+
# Methods <code>Regexp#as_json</code> and <code>Regexp.json_create</code> may be
|
|
1737
|
+
# used to serialize and deserialize a Regexp object; see
|
|
1738
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1700
1739
|
#
|
|
1701
|
-
# Method
|
|
1702
|
-
# representing `self`:
|
|
1740
|
+
# Method <code>Regexp#as_json</code> serializes `self`, returning a 2-element
|
|
1741
|
+
# hash representing `self`:
|
|
1703
1742
|
#
|
|
1704
1743
|
# require 'json/add/regexp'
|
|
1705
1744
|
# x = /foo/.as_json
|
|
1706
1745
|
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
|
1707
1746
|
#
|
|
1708
|
-
# Method
|
|
1747
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Regexp
|
|
1748
|
+
# object:
|
|
1709
1749
|
#
|
|
1710
1750
|
# Regexp.json_create(x) # => /foo/
|
|
1711
1751
|
#
|
|
@@ -1724,7 +1764,7 @@ class Regexp
|
|
|
1724
1764
|
#
|
|
1725
1765
|
# {"json_class":"Regexp","o":0,"s":"foo"}
|
|
1726
1766
|
#
|
|
1727
|
-
def to_json: (?JSON::State state) -> String
|
|
1767
|
+
def to_json: (?JSON::State? state) -> String
|
|
1728
1768
|
end
|
|
1729
1769
|
|
|
1730
1770
|
%a{annotate:rdoc:skip}
|
|
@@ -1741,17 +1781,18 @@ class Set[unchecked out A]
|
|
|
1741
1781
|
# rdoc-file=ext/json/lib/json/add/set.rb
|
|
1742
1782
|
# - as_json(*)
|
|
1743
1783
|
# -->
|
|
1744
|
-
# Methods
|
|
1745
|
-
# deserialize a Set object; see [Marshal](rdoc-ref:Marshal).
|
|
1784
|
+
# Methods <code>Set#as_json</code> and <code>Set.json_create</code> may be used
|
|
1785
|
+
# to serialize and deserialize a Set object; see [Marshal](rdoc-ref:Marshal).
|
|
1746
1786
|
#
|
|
1747
|
-
# Method
|
|
1787
|
+
# Method <code>Set#as_json</code> serializes `self`, returning a 2-element hash
|
|
1748
1788
|
# representing `self`:
|
|
1749
1789
|
#
|
|
1750
1790
|
# require 'json/add/set'
|
|
1751
1791
|
# x = Set.new(%w/foo bar baz/).as_json
|
|
1752
1792
|
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
|
1753
1793
|
#
|
|
1754
|
-
# Method
|
|
1794
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Set
|
|
1795
|
+
# object:
|
|
1755
1796
|
#
|
|
1756
1797
|
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
|
1757
1798
|
#
|
|
@@ -1770,40 +1811,42 @@ class Set[unchecked out A]
|
|
|
1770
1811
|
#
|
|
1771
1812
|
# {"json_class":"Set","a":["foo","bar","baz"]}
|
|
1772
1813
|
#
|
|
1773
|
-
def to_json: (?JSON::State state) -> String
|
|
1814
|
+
def to_json: (?JSON::State? state) -> String
|
|
1774
1815
|
end
|
|
1775
1816
|
|
|
1776
1817
|
%a{annotate:rdoc:skip}
|
|
1777
|
-
class Struct[
|
|
1818
|
+
class Struct[E]
|
|
1778
1819
|
# <!--
|
|
1779
1820
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
|
1780
1821
|
# - json_create(object)
|
|
1781
1822
|
# -->
|
|
1782
1823
|
# See #as_json.
|
|
1783
1824
|
#
|
|
1784
|
-
def self.json_create: [
|
|
1825
|
+
def self.json_create: [E] (Hash[String, String | Array[E]] object) -> Struct[E]
|
|
1785
1826
|
|
|
1786
1827
|
# <!--
|
|
1787
1828
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
|
1788
1829
|
# - as_json(*)
|
|
1789
1830
|
# -->
|
|
1790
|
-
# Methods
|
|
1791
|
-
# deserialize a Struct object; see
|
|
1831
|
+
# Methods <code>Struct#as_json</code> and <code>Struct.json_create</code> may be
|
|
1832
|
+
# used to serialize and deserialize a Struct object; see
|
|
1833
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1792
1834
|
#
|
|
1793
|
-
# Method
|
|
1794
|
-
# representing `self`:
|
|
1835
|
+
# Method <code>Struct#as_json</code> serializes `self`, returning a 2-element
|
|
1836
|
+
# hash representing `self`:
|
|
1795
1837
|
#
|
|
1796
1838
|
# require 'json/add/struct'
|
|
1797
1839
|
# Customer = Struct.new('Customer', :name, :address, :zip)
|
|
1798
1840
|
# x = Struct::Customer.new.as_json
|
|
1799
1841
|
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
|
1800
1842
|
#
|
|
1801
|
-
# Method
|
|
1843
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Struct
|
|
1844
|
+
# object:
|
|
1802
1845
|
#
|
|
1803
1846
|
# Struct::Customer.json_create(x)
|
|
1804
1847
|
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
|
1805
1848
|
#
|
|
1806
|
-
def as_json: (*untyped) -> Hash[String, String | Array[
|
|
1849
|
+
def as_json: (*untyped) -> Hash[String, String | Array[E]]
|
|
1807
1850
|
|
|
1808
1851
|
# <!--
|
|
1809
1852
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
|
@@ -1819,7 +1862,7 @@ class Struct[Elem]
|
|
|
1819
1862
|
#
|
|
1820
1863
|
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
|
1821
1864
|
#
|
|
1822
|
-
def to_json: (?JSON::State state) -> String
|
|
1865
|
+
def to_json: (?JSON::State? state) -> String
|
|
1823
1866
|
end
|
|
1824
1867
|
|
|
1825
1868
|
%a{annotate:rdoc:skip}
|
|
@@ -1836,17 +1879,19 @@ class Symbol
|
|
|
1836
1879
|
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
|
1837
1880
|
# - as_json(*)
|
|
1838
1881
|
# -->
|
|
1839
|
-
# Methods
|
|
1840
|
-
# deserialize a Symbol object; see
|
|
1882
|
+
# Methods <code>Symbol#as_json</code> and <code>Symbol.json_create</code> may be
|
|
1883
|
+
# used to serialize and deserialize a Symbol object; see
|
|
1884
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1841
1885
|
#
|
|
1842
|
-
# Method
|
|
1843
|
-
# representing `self`:
|
|
1886
|
+
# Method <code>Symbol#as_json</code> serializes `self`, returning a 2-element
|
|
1887
|
+
# hash representing `self`:
|
|
1844
1888
|
#
|
|
1845
1889
|
# require 'json/add/symbol'
|
|
1846
1890
|
# x = :foo.as_json
|
|
1847
1891
|
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
|
1848
1892
|
#
|
|
1849
|
-
# Method
|
|
1893
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Symbol
|
|
1894
|
+
# object:
|
|
1850
1895
|
#
|
|
1851
1896
|
# Symbol.json_create(x) # => :foo
|
|
1852
1897
|
#
|
|
@@ -1854,7 +1899,7 @@ class Symbol
|
|
|
1854
1899
|
|
|
1855
1900
|
# <!--
|
|
1856
1901
|
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
|
1857
|
-
# - to_json(*a)
|
|
1902
|
+
# - to_json(state = nil, *a)
|
|
1858
1903
|
# -->
|
|
1859
1904
|
# Returns a JSON string representing `self`:
|
|
1860
1905
|
#
|
|
@@ -1865,7 +1910,7 @@ class Symbol
|
|
|
1865
1910
|
#
|
|
1866
1911
|
# # {"json_class":"Symbol","s":"foo"}
|
|
1867
1912
|
#
|
|
1868
|
-
def to_json: (?JSON::State state) -> String
|
|
1913
|
+
def to_json: (?JSON::State? state) -> String
|
|
1869
1914
|
end
|
|
1870
1915
|
|
|
1871
1916
|
%a{annotate:rdoc:skip}
|
|
@@ -1882,17 +1927,19 @@ class Time
|
|
|
1882
1927
|
# rdoc-file=ext/json/lib/json/add/time.rb
|
|
1883
1928
|
# - as_json(*)
|
|
1884
1929
|
# -->
|
|
1885
|
-
# Methods
|
|
1886
|
-
# deserialize a Time object; see
|
|
1930
|
+
# Methods <code>Time#as_json</code> and <code>Time.json_create</code> may be
|
|
1931
|
+
# used to serialize and deserialize a Time object; see
|
|
1932
|
+
# [Marshal](rdoc-ref:Marshal).
|
|
1887
1933
|
#
|
|
1888
|
-
# Method
|
|
1934
|
+
# Method <code>Time#as_json</code> serializes `self`, returning a 2-element hash
|
|
1889
1935
|
# representing `self`:
|
|
1890
1936
|
#
|
|
1891
1937
|
# require 'json/add/time'
|
|
1892
1938
|
# x = Time.now.as_json
|
|
1893
1939
|
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
|
1894
1940
|
#
|
|
1895
|
-
# Method
|
|
1941
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Time
|
|
1942
|
+
# object:
|
|
1896
1943
|
#
|
|
1897
1944
|
# Time.json_create(x)
|
|
1898
1945
|
# # => 2023-11-25 11:00:56.472846644 -0600
|
|
@@ -1912,5 +1959,5 @@ class Time
|
|
|
1912
1959
|
#
|
|
1913
1960
|
# {"json_class":"Time","s":1700931678,"n":980650786}
|
|
1914
1961
|
#
|
|
1915
|
-
def to_json: (?JSON::State state) -> String
|
|
1962
|
+
def to_json: (?JSON::State? state) -> String
|
|
1916
1963
|
end
|