rbs 3.10.4 → 4.0.0
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/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +7 -5
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +16 -26
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +2 -2
- data/.vscode/extensions.json +5 -0
- data/.vscode/settings.json +19 -0
- data/CHANGELOG.md +202 -2
- data/Rakefile +9 -23
- data/Steepfile +2 -0
- data/config.yml +457 -13
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +66 -55
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +6 -6
- data/core/enumerable.rbs +105 -91
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +24 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +47 -36
- data/core/file.rbs +242 -169
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +42 -68
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -75
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +192 -146
- data/core/kernel.rbs +198 -147
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -8
- data/core/module.rbs +148 -88
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +53 -50
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -34
- data/core/process.rbs +221 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +21 -3
- data/core/range.rbs +152 -49
- data/core/rational.rbs +5 -56
- data/core/rbs/unnamed/argf.rbs +58 -51
- data/core/rbs/unnamed/env_class.rbs +18 -13
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +7 -116
- data/core/regexp.rbs +236 -197
- data/core/ruby.rbs +1 -1
- data/core/ruby_vm.rbs +32 -30
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +1 -1
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +5 -3
- data/core/set.rbs +17 -16
- data/core/signal.rbs +2 -2
- data/core/string.rbs +318 -298
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -41
- data/core/time.rbs +47 -42
- data/core/trace_point.rbs +34 -31
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +10 -10
- data/core/warning.rbs +7 -7
- data/docs/collection.md +1 -1
- data/docs/config.md +171 -0
- data/docs/inline.md +576 -0
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +595 -98
- data/ext/rbs_extension/class_constants.c +30 -0
- data/ext/rbs_extension/class_constants.h +15 -0
- data/ext/rbs_extension/legacy_location.c +30 -53
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +125 -24
- data/include/rbs/ast.h +485 -150
- data/include/rbs/lexer.h +11 -4
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +20 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- 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 +409 -0
- data/lib/rbs/ast/ruby/comment_block.rb +245 -0
- data/lib/rbs/ast/ruby/declarations.rb +281 -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 +723 -0
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +105 -20
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +62 -125
- data/lib/rbs/cli.rb +55 -23
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -4
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +119 -63
- data/lib/rbs/definition_builder/method_builder.rb +65 -30
- 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 +338 -155
- data/lib/rbs/environment_loader.rb +2 -2
- data/lib/rbs/errors.rb +30 -20
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +542 -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 +0 -7
- data/lib/rbs/parser_aux.rb +31 -8
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +10 -2
- data/lib/rbs/resolver/type_name_resolver.rb +0 -8
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +5 -2
- data/lib/rbs/type_name.rb +1 -8
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +12 -1
- data/rbs.gemspec +3 -2
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/schema/typeParam.json +17 -1
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +421 -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 +178 -0
- data/sig/buffer.rbs +63 -5
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- 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 +37 -81
- data/sig/errors.rbs +26 -20
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +124 -0
- data/sig/location.rbs +32 -7
- data/sig/locator.rbs +0 -2
- data/sig/method_builder.rbs +9 -4
- data/sig/namespace.rbs +0 -5
- data/sig/parser.rbs +47 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +0 -3
- data/sig/source.rbs +48 -0
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +0 -5
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +491 -143
- data/src/lexer.c +1552 -1314
- data/src/lexer.re +7 -0
- data/src/lexstate.c +8 -1
- data/src/location.c +8 -48
- data/src/parser.c +1107 -409
- data/src/util/rbs_constant_pool.c +0 -4
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
- data/stdlib/cgi-escape/0/escape.rbs +4 -4
- data/stdlib/coverage/0/coverage.rbs +4 -3
- data/stdlib/date/0/date.rbs +33 -28
- data/stdlib/date/0/date_time.rbs +24 -23
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +140 -126
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +158 -131
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +159 -134
- data/stdlib/objspace/0/objspace.rbs +8 -30
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +23 -14
- data/stdlib/pathname/0/pathname.rbs +2 -2
- 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 +62 -9
- 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 +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- 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 +10 -9
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +1 -1
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +55 -54
- data/stdlib/strscan/0/string_scanner.rbs +46 -44
- data/stdlib/tempfile/0/tempfile.rbs +24 -20
- data/stdlib/time/0/time.rbs +7 -5
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +31 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +9 -2
- 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 +6 -5
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +6 -6
- 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
- metadata +66 -3
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 -->
|
|
@@ -79,8 +79,8 @@ end
|
|
|
79
79
|
# JSON is a lightweight data-interchange format.
|
|
80
80
|
#
|
|
81
81
|
# A JSON value is one of the following:
|
|
82
|
-
# * Double-quoted text:
|
|
83
|
-
# * Number: `1`,
|
|
82
|
+
# * Double-quoted text: <code>"foo"</code>.
|
|
83
|
+
# * Number: `1`, <code>1.0</code>, <code>2.0e2</code>.
|
|
84
84
|
# * Boolean: `true`, `false`.
|
|
85
85
|
# * Null: `null`.
|
|
86
86
|
# * Array: an ordered list of values, enclosed by square brackets:
|
|
@@ -105,8 +105,8 @@ end
|
|
|
105
105
|
# ### Parsing JSON
|
|
106
106
|
#
|
|
107
107
|
# You can parse a String containing JSON data using either of two methods:
|
|
108
|
-
# *
|
|
109
|
-
# *
|
|
108
|
+
# * <code>JSON.parse(source, opts)</code>
|
|
109
|
+
# * <code>JSON.parse!(source, opts)</code>
|
|
110
110
|
#
|
|
111
111
|
# where
|
|
112
112
|
# * `source` is a Ruby object.
|
|
@@ -292,12 +292,12 @@ end
|
|
|
292
292
|
# ---
|
|
293
293
|
#
|
|
294
294
|
# Option `create_additions` (boolean) specifies whether to use JSON additions in
|
|
295
|
-
# parsing. See [
|
|
295
|
+
# parsing. See [JSON Additions](#module-JSON-label-JSON+Additions).
|
|
296
296
|
#
|
|
297
297
|
# ### Generating JSON
|
|
298
298
|
#
|
|
299
299
|
# To generate a Ruby String containing JSON data, use method
|
|
300
|
-
#
|
|
300
|
+
# <code>JSON.generate(source, opts)</code>, where
|
|
301
301
|
# * `source` is a Ruby object.
|
|
302
302
|
# * `opts` is a Hash object containing options that control both input allowed
|
|
303
303
|
# and output formatting.
|
|
@@ -361,7 +361,7 @@ end
|
|
|
361
361
|
# ###### Input Options
|
|
362
362
|
#
|
|
363
363
|
# Option `allow_nan` (boolean) specifies whether `NaN`, `Infinity`, and
|
|
364
|
-
#
|
|
364
|
+
# <code>-Infinity</code> may be generated; defaults to `false`.
|
|
365
365
|
#
|
|
366
366
|
# With the default, `false`:
|
|
367
367
|
# # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
|
|
@@ -409,9 +409,9 @@ end
|
|
|
409
409
|
#
|
|
410
410
|
# ###### Escaping Options
|
|
411
411
|
#
|
|
412
|
-
# Options `script_safe` (boolean) specifies wether
|
|
413
|
-
#
|
|
414
|
-
# 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.
|
|
415
415
|
#
|
|
416
416
|
# Options `ascii_only` (boolean) specifies wether all characters outside the
|
|
417
417
|
# ASCII range should be escaped.
|
|
@@ -425,19 +425,21 @@ end
|
|
|
425
425
|
# format, using whitespace. See also JSON.pretty_generate.
|
|
426
426
|
#
|
|
427
427
|
# * Option `array_nl` (String) specifies a string (usually a newline) to be
|
|
428
|
-
# inserted after each JSON array; defaults to the empty String,
|
|
428
|
+
# inserted after each JSON array; defaults to the empty String,
|
|
429
|
+
# <code>''</code>.
|
|
429
430
|
# * Option `object_nl` (String) specifies a string (usually a newline) to be
|
|
430
|
-
# inserted after each JSON object; defaults to the empty String,
|
|
431
|
+
# inserted after each JSON object; defaults to the empty String,
|
|
432
|
+
# <code>''</code>.
|
|
431
433
|
# * Option `indent` (String) specifies the string (usually spaces) to be used
|
|
432
|
-
# for indentation; defaults to the empty String,
|
|
433
|
-
# String,
|
|
434
|
-
# 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.
|
|
435
437
|
# * Option `space` (String) specifies a string (usually a space) to be
|
|
436
438
|
# inserted after the colon in each JSON object's pair; defaults to the empty
|
|
437
|
-
# String,
|
|
439
|
+
# String, <code>''</code>.
|
|
438
440
|
# * Option `space_before` (String) specifies a string (usually a space) to be
|
|
439
441
|
# inserted before the colon in each JSON object's pair; defaults to the
|
|
440
|
-
# empty String,
|
|
442
|
+
# empty String, <code>''</code>.
|
|
441
443
|
#
|
|
442
444
|
# In this example, `obj` is used first to generate the shortest JSON data (no
|
|
443
445
|
# whitespace), then again with all formatting options specified:
|
|
@@ -519,26 +521,26 @@ end
|
|
|
519
521
|
# With addition: 0..2 (Range)
|
|
520
522
|
#
|
|
521
523
|
# The JSON module includes additions for certain classes. You can also craft
|
|
522
|
-
# custom additions. See [Custom
|
|
524
|
+
# custom additions. See [Custom JSON
|
|
523
525
|
# Additions](#module-JSON-label-Custom+JSON+Additions).
|
|
524
526
|
#
|
|
525
527
|
# ### Built-in Additions
|
|
526
528
|
#
|
|
527
529
|
# The JSON module includes additions for certain classes. To use an addition,
|
|
528
530
|
# `require` its source:
|
|
529
|
-
# * BigDecimal:
|
|
530
|
-
# * Complex:
|
|
531
|
-
# * Date:
|
|
532
|
-
# * DateTime:
|
|
533
|
-
# * Exception:
|
|
534
|
-
# * OpenStruct:
|
|
535
|
-
# * Range:
|
|
536
|
-
# * Rational:
|
|
537
|
-
# * Regexp:
|
|
538
|
-
# * Set:
|
|
539
|
-
# * Struct:
|
|
540
|
-
# * Symbol:
|
|
541
|
-
# * 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>
|
|
542
544
|
#
|
|
543
545
|
# To reduce punctuation clutter, the examples below show the generated JSON via
|
|
544
546
|
# `puts`, rather than the usual `inspect`,
|
|
@@ -857,7 +859,7 @@ module JSON
|
|
|
857
859
|
# json = JSON.generate(obj)
|
|
858
860
|
# json # => '{"foo":0,"bar":"s","baz":"bat"}'
|
|
859
861
|
#
|
|
860
|
-
# For examples of generating from other Ruby objects, see [Generating
|
|
862
|
+
# For examples of generating from other Ruby objects, see [Generating JSON from
|
|
861
863
|
# Other Objects](#module-JSON-label-Generating+JSON+from+Other+Objects).
|
|
862
864
|
#
|
|
863
865
|
# ---
|
|
@@ -895,15 +897,17 @@ module JSON
|
|
|
895
897
|
# in JSON version 3.0, `load` will have `create_additions` disabled by default.
|
|
896
898
|
#
|
|
897
899
|
# * Argument `source` must be, or be convertible to, a String:
|
|
898
|
-
# * If `source` responds to instance method `to_str`,
|
|
899
|
-
# becomes the source.
|
|
900
|
-
# * If `source` responds to instance method `to_io`,
|
|
901
|
-
# becomes the source.
|
|
902
|
-
# * If `source` responds to instance method `read`,
|
|
903
|
-
# the source.
|
|
904
|
-
# * 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>:
|
|
905
908
|
# * Option `allow_blank` specifies a truthy value.
|
|
906
|
-
# * 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>.
|
|
907
911
|
# * Otherwise, `source` remains the source.
|
|
908
912
|
# * Argument `proc`, if given, must be a Proc that accepts one argument. It
|
|
909
913
|
# will be called recursively with each result (depth-first order). See
|
|
@@ -915,7 +919,7 @@ module JSON
|
|
|
915
919
|
# ---
|
|
916
920
|
#
|
|
917
921
|
# When no `proc` is given, modifies `source` as above and returns the result of
|
|
918
|
-
#
|
|
922
|
+
# <code>parse(source, opts)</code>; see #parse.
|
|
919
923
|
#
|
|
920
924
|
# Source for following examples:
|
|
921
925
|
# source = <<~JSON
|
|
@@ -950,8 +954,8 @@ module JSON
|
|
|
950
954
|
#
|
|
951
955
|
# When `proc` is given:
|
|
952
956
|
# * Modifies `source` as above.
|
|
953
|
-
# * Gets the `result` from calling
|
|
954
|
-
# * Recursively calls
|
|
957
|
+
# * Gets the `result` from calling <code>parse(source, opts)</code>.
|
|
958
|
+
# * Recursively calls <code>proc(result)</code>.
|
|
955
959
|
# * Returns the final result.
|
|
956
960
|
#
|
|
957
961
|
# Example:
|
|
@@ -1083,7 +1087,7 @@ module JSON
|
|
|
1083
1087
|
# ruby.class # => Hash
|
|
1084
1088
|
#
|
|
1085
1089
|
# For examples of parsing for all JSON data types, see [Parsing
|
|
1086
|
-
#
|
|
1090
|
+
# JSON](#module-JSON-label-Parsing+JSON).
|
|
1087
1091
|
#
|
|
1088
1092
|
# Parses nested JSON objects:
|
|
1089
1093
|
# source = <<~JSON
|
|
@@ -1245,28 +1249,28 @@ class Object
|
|
|
1245
1249
|
# it to a JSON string, and returns the result. This is a fallback, if no
|
|
1246
1250
|
# special method #to_json was defined for some object.
|
|
1247
1251
|
#
|
|
1248
|
-
def to_json: (?JSON::State state) -> String
|
|
1252
|
+
def to_json: (?JSON::State? state) -> String
|
|
1249
1253
|
end
|
|
1250
1254
|
|
|
1251
1255
|
%a{annotate:rdoc:skip}
|
|
1252
1256
|
class NilClass
|
|
1253
1257
|
# Returns a JSON string for nil: 'null'.
|
|
1254
1258
|
#
|
|
1255
|
-
def to_json: (?JSON::State state) -> String
|
|
1259
|
+
def to_json: (?JSON::State? state) -> String
|
|
1256
1260
|
end
|
|
1257
1261
|
|
|
1258
1262
|
%a{annotate:rdoc:skip}
|
|
1259
1263
|
class TrueClass
|
|
1260
1264
|
# Returns a JSON string for true: 'true'.
|
|
1261
1265
|
#
|
|
1262
|
-
def to_json: (?JSON::State state) -> String
|
|
1266
|
+
def to_json: (?JSON::State? state) -> String
|
|
1263
1267
|
end
|
|
1264
1268
|
|
|
1265
1269
|
%a{annotate:rdoc:skip}
|
|
1266
1270
|
class FalseClass
|
|
1267
1271
|
# Returns a JSON string for false: 'false'.
|
|
1268
1272
|
#
|
|
1269
|
-
def to_json: (?JSON::State state) -> String
|
|
1273
|
+
def to_json: (?JSON::State? state) -> String
|
|
1270
1274
|
end
|
|
1271
1275
|
|
|
1272
1276
|
%a{annotate:rdoc:skip}
|
|
@@ -1275,21 +1279,21 @@ class String
|
|
|
1275
1279
|
# returns a JSON string encoded with UTF16 big endian characters as
|
|
1276
1280
|
# \u????.
|
|
1277
1281
|
#
|
|
1278
|
-
def to_json: (?JSON::State state) -> String
|
|
1282
|
+
def to_json: (?JSON::State? state) -> String
|
|
1279
1283
|
end
|
|
1280
1284
|
|
|
1281
1285
|
%a{annotate:rdoc:skip}
|
|
1282
1286
|
class Integer
|
|
1283
1287
|
# Returns a JSON string representation for this Integer number.
|
|
1284
1288
|
#
|
|
1285
|
-
def to_json: (?JSON::State state) -> String
|
|
1289
|
+
def to_json: (?JSON::State? state) -> String
|
|
1286
1290
|
end
|
|
1287
1291
|
|
|
1288
1292
|
%a{annotate:rdoc:skip}
|
|
1289
1293
|
class Float
|
|
1290
1294
|
# Returns a JSON string representation for this Float number.
|
|
1291
1295
|
#
|
|
1292
|
-
def to_json: (?JSON::State state) -> String
|
|
1296
|
+
def to_json: (?JSON::State? state) -> String
|
|
1293
1297
|
end
|
|
1294
1298
|
|
|
1295
1299
|
%a{annotate:rdoc:skip}
|
|
@@ -1299,7 +1303,7 @@ class Hash[unchecked out K, unchecked out V]
|
|
|
1299
1303
|
# _state_ is a JSON::State object, that can also be used to configure the
|
|
1300
1304
|
# produced JSON string output further.
|
|
1301
1305
|
#
|
|
1302
|
-
def to_json: (?JSON::State state) -> String
|
|
1306
|
+
def to_json: (?JSON::State? state) -> String
|
|
1303
1307
|
end
|
|
1304
1308
|
|
|
1305
1309
|
%a{annotate:rdoc:skip}
|
|
@@ -1309,7 +1313,7 @@ class Array[unchecked out Elem]
|
|
|
1309
1313
|
# _state_ is a JSON::State object, that can also be used to configure the
|
|
1310
1314
|
# produced JSON string output further.
|
|
1311
1315
|
#
|
|
1312
|
-
def to_json: (?JSON::State state) -> String
|
|
1316
|
+
def to_json: (?JSON::State? state) -> String
|
|
1313
1317
|
end
|
|
1314
1318
|
|
|
1315
1319
|
%a{annotate:rdoc:skip}
|
|
@@ -1326,19 +1330,20 @@ class BigDecimal
|
|
|
1326
1330
|
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
|
1327
1331
|
# - as_json(*)
|
|
1328
1332
|
# -->
|
|
1329
|
-
# Methods
|
|
1330
|
-
# serialize and deserialize a
|
|
1331
|
-
# [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).
|
|
1332
1336
|
#
|
|
1333
|
-
# Method
|
|
1334
|
-
# representing `self`:
|
|
1337
|
+
# Method <code>BigDecimal#as_json</code> serializes `self`, returning a
|
|
1338
|
+
# 2-element hash representing `self`:
|
|
1335
1339
|
#
|
|
1336
1340
|
# require 'json/add/bigdecimal'
|
|
1337
1341
|
# x = BigDecimal(2).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
|
1338
1342
|
# y = BigDecimal(2.0, 4).as_json # => {"json_class"=>"BigDecimal", "b"=>"36:0.2e1"}
|
|
1339
1343
|
# z = BigDecimal(Complex(2, 0)).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
|
1340
1344
|
#
|
|
1341
|
-
# Method
|
|
1345
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a
|
|
1346
|
+
# BigDecimal object:
|
|
1342
1347
|
#
|
|
1343
1348
|
# BigDecimal.json_create(x) # => 0.2e1
|
|
1344
1349
|
# BigDecimal.json_create(y) # => 0.2e1
|
|
@@ -1363,7 +1368,7 @@ class BigDecimal
|
|
|
1363
1368
|
# {"json_class":"BigDecimal","b":"36:0.2e1"}
|
|
1364
1369
|
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
|
1365
1370
|
#
|
|
1366
|
-
def to_json: (?JSON::State state) -> String
|
|
1371
|
+
def to_json: (?JSON::State? state) -> String
|
|
1367
1372
|
end
|
|
1368
1373
|
|
|
1369
1374
|
%a{annotate:rdoc:skip}
|
|
@@ -1380,17 +1385,19 @@ class Complex
|
|
|
1380
1385
|
# rdoc-file=ext/json/lib/json/add/complex.rb
|
|
1381
1386
|
# - as_json(*)
|
|
1382
1387
|
# -->
|
|
1383
|
-
# Methods
|
|
1384
|
-
# 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).
|
|
1385
1391
|
#
|
|
1386
|
-
# Method
|
|
1387
|
-
# representing `self`:
|
|
1392
|
+
# Method <code>Complex#as_json</code> serializes `self`, returning a 2-element
|
|
1393
|
+
# hash representing `self`:
|
|
1388
1394
|
#
|
|
1389
1395
|
# require 'json/add/complex'
|
|
1390
1396
|
# x = Complex(2).as_json # => {"json_class"=>"Complex", "r"=>2, "i"=>0}
|
|
1391
1397
|
# y = Complex(2.0, 4).as_json # => {"json_class"=>"Complex", "r"=>2.0, "i"=>4}
|
|
1392
1398
|
#
|
|
1393
|
-
# Method
|
|
1399
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Complex
|
|
1400
|
+
# object:
|
|
1394
1401
|
#
|
|
1395
1402
|
# Complex.json_create(x) # => (2+0i)
|
|
1396
1403
|
# Complex.json_create(y) # => (2.0+4i)
|
|
@@ -1412,7 +1419,7 @@ class Complex
|
|
|
1412
1419
|
# {"json_class":"Complex","r":2,"i":0}
|
|
1413
1420
|
# {"json_class":"Complex","r":2.0,"i":4}
|
|
1414
1421
|
#
|
|
1415
|
-
def to_json: (?JSON::State state) -> String
|
|
1422
|
+
def to_json: (?JSON::State? state) -> String
|
|
1416
1423
|
end
|
|
1417
1424
|
|
|
1418
1425
|
%a{annotate:rdoc:skip}
|
|
@@ -1429,17 +1436,19 @@ class Date
|
|
|
1429
1436
|
# rdoc-file=ext/json/lib/json/add/date.rb
|
|
1430
1437
|
# - as_json(*)
|
|
1431
1438
|
# -->
|
|
1432
|
-
# Methods
|
|
1433
|
-
# 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).
|
|
1434
1442
|
#
|
|
1435
|
-
# Method
|
|
1443
|
+
# Method <code>Date#as_json</code> serializes `self`, returning a 2-element hash
|
|
1436
1444
|
# representing `self`:
|
|
1437
1445
|
#
|
|
1438
1446
|
# require 'json/add/date'
|
|
1439
1447
|
# x = Date.today.as_json
|
|
1440
1448
|
# # => {"json_class"=>"Date", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
|
1441
1449
|
#
|
|
1442
|
-
# Method
|
|
1450
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Date
|
|
1451
|
+
# object:
|
|
1443
1452
|
#
|
|
1444
1453
|
# Date.json_create(x)
|
|
1445
1454
|
# # => #<Date: 2023-11-21 ((2460270j,0s,0n),+0s,2299161j)>
|
|
@@ -1459,7 +1468,7 @@ class Date
|
|
|
1459
1468
|
#
|
|
1460
1469
|
# {"json_class":"Date","y":2023,"m":11,"d":21,"sg":2299161.0}
|
|
1461
1470
|
#
|
|
1462
|
-
def to_json: (?JSON::State state) -> String
|
|
1471
|
+
def to_json: (?JSON::State? state) -> String
|
|
1463
1472
|
end
|
|
1464
1473
|
|
|
1465
1474
|
%a{annotate:rdoc:skip}
|
|
@@ -1476,17 +1485,19 @@ class DateTime
|
|
|
1476
1485
|
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
|
1477
1486
|
# - as_json(*)
|
|
1478
1487
|
# -->
|
|
1479
|
-
# Methods
|
|
1480
|
-
# 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).
|
|
1481
1491
|
#
|
|
1482
|
-
# Method
|
|
1483
|
-
# representing `self`:
|
|
1492
|
+
# Method <code>DateTime#as_json</code> serializes `self`, returning a 2-element
|
|
1493
|
+
# hash representing `self`:
|
|
1484
1494
|
#
|
|
1485
1495
|
# require 'json/add/datetime'
|
|
1486
1496
|
# x = DateTime.now.as_json
|
|
1487
1497
|
# # => {"json_class"=>"DateTime", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
|
1488
1498
|
#
|
|
1489
|
-
# Method
|
|
1499
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a DateTime
|
|
1500
|
+
# object:
|
|
1490
1501
|
#
|
|
1491
1502
|
# DateTime.json_create(x) # BUG? Raises Date::Error "invalid date"
|
|
1492
1503
|
#
|
|
@@ -1505,7 +1516,7 @@ class DateTime
|
|
|
1505
1516
|
#
|
|
1506
1517
|
# {"json_class":"DateTime","y":2023,"m":11,"d":21,"sg":2299161.0}
|
|
1507
1518
|
#
|
|
1508
|
-
def to_json: (?JSON::State state) -> String
|
|
1519
|
+
def to_json: (?JSON::State? state) -> String
|
|
1509
1520
|
end
|
|
1510
1521
|
|
|
1511
1522
|
%a{annotate:rdoc:skip}
|
|
@@ -1522,16 +1533,18 @@ class Exception
|
|
|
1522
1533
|
# rdoc-file=ext/json/lib/json/add/exception.rb
|
|
1523
1534
|
# - as_json(*)
|
|
1524
1535
|
# -->
|
|
1525
|
-
# Methods
|
|
1526
|
-
# 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).
|
|
1527
1539
|
#
|
|
1528
|
-
# Method
|
|
1529
|
-
# representing `self`:
|
|
1540
|
+
# Method <code>Exception#as_json</code> serializes `self`, returning a 2-element
|
|
1541
|
+
# hash representing `self`:
|
|
1530
1542
|
#
|
|
1531
1543
|
# require 'json/add/exception'
|
|
1532
1544
|
# x = Exception.new('Foo').as_json # => {"json_class"=>"Exception", "m"=>"Foo", "b"=>nil}
|
|
1533
1545
|
#
|
|
1534
|
-
# Method
|
|
1546
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a
|
|
1547
|
+
# Exception object:
|
|
1535
1548
|
#
|
|
1536
1549
|
# Exception.json_create(x) # => #<Exception: Foo>
|
|
1537
1550
|
#
|
|
@@ -1550,7 +1563,7 @@ class Exception
|
|
|
1550
1563
|
#
|
|
1551
1564
|
# {"json_class":"Exception","m":"Foo","b":null}
|
|
1552
1565
|
#
|
|
1553
|
-
def to_json: (?JSON::State state) -> String
|
|
1566
|
+
def to_json: (?JSON::State? state) -> String
|
|
1554
1567
|
end
|
|
1555
1568
|
|
|
1556
1569
|
%a{annotate:rdoc:skip}
|
|
@@ -1567,18 +1580,19 @@ class OpenStruct
|
|
|
1567
1580
|
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
|
1568
1581
|
# - as_json(*)
|
|
1569
1582
|
# -->
|
|
1570
|
-
# Methods
|
|
1571
|
-
# serialize and deserialize a
|
|
1572
|
-
# [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).
|
|
1573
1586
|
#
|
|
1574
|
-
# Method
|
|
1575
|
-
# representing `self`:
|
|
1587
|
+
# Method <code>OpenStruct#as_json</code> serializes `self`, returning a
|
|
1588
|
+
# 2-element hash representing `self`:
|
|
1576
1589
|
#
|
|
1577
1590
|
# require 'json/add/ostruct'
|
|
1578
1591
|
# x = OpenStruct.new('name' => 'Rowdy', :age => nil).as_json
|
|
1579
1592
|
# # => {"json_class"=>"OpenStruct", "t"=>{:name=>'Rowdy', :age=>nil}}
|
|
1580
1593
|
#
|
|
1581
|
-
# Method
|
|
1594
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a
|
|
1595
|
+
# OpenStruct object:
|
|
1582
1596
|
#
|
|
1583
1597
|
# OpenStruct.json_create(x)
|
|
1584
1598
|
# # => #<OpenStruct name='Rowdy', age=nil>
|
|
@@ -1598,7 +1612,7 @@ class OpenStruct
|
|
|
1598
1612
|
#
|
|
1599
1613
|
# {"json_class":"OpenStruct","t":{'name':'Rowdy',"age":null}}
|
|
1600
1614
|
#
|
|
1601
|
-
def to_json: (?JSON::State state) -> String
|
|
1615
|
+
def to_json: (?JSON::State? state) -> String
|
|
1602
1616
|
end
|
|
1603
1617
|
|
|
1604
1618
|
%a{annotate:rdoc:skip}
|
|
@@ -1615,18 +1629,20 @@ class Range[out Elem]
|
|
|
1615
1629
|
# rdoc-file=ext/json/lib/json/add/range.rb
|
|
1616
1630
|
# - as_json(*)
|
|
1617
1631
|
# -->
|
|
1618
|
-
# Methods
|
|
1619
|
-
# 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).
|
|
1620
1635
|
#
|
|
1621
|
-
# Method
|
|
1622
|
-
# representing `self`:
|
|
1636
|
+
# Method <code>Range#as_json</code> serializes `self`, returning a 2-element
|
|
1637
|
+
# hash representing `self`:
|
|
1623
1638
|
#
|
|
1624
1639
|
# require 'json/add/range'
|
|
1625
1640
|
# x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
|
1626
1641
|
# y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
|
1627
1642
|
# z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
|
1628
1643
|
#
|
|
1629
|
-
# Method
|
|
1644
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Range
|
|
1645
|
+
# object:
|
|
1630
1646
|
#
|
|
1631
1647
|
# Range.json_create(x) # => 1..4
|
|
1632
1648
|
# Range.json_create(y) # => 1...4
|
|
@@ -1651,7 +1667,7 @@ class Range[out Elem]
|
|
|
1651
1667
|
# {"json_class":"Range","a":[1,4,true]}
|
|
1652
1668
|
# {"json_class":"Range","a":["a","d",false]}
|
|
1653
1669
|
#
|
|
1654
|
-
def to_json: (?JSON::State state) -> String
|
|
1670
|
+
def to_json: (?JSON::State? state) -> String
|
|
1655
1671
|
end
|
|
1656
1672
|
|
|
1657
1673
|
%a{annotate:rdoc:skip}
|
|
@@ -1668,17 +1684,19 @@ class Rational
|
|
|
1668
1684
|
# rdoc-file=ext/json/lib/json/add/rational.rb
|
|
1669
1685
|
# - as_json(*)
|
|
1670
1686
|
# -->
|
|
1671
|
-
# Methods
|
|
1672
|
-
# 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).
|
|
1673
1690
|
#
|
|
1674
|
-
# Method
|
|
1675
|
-
# representing `self`:
|
|
1691
|
+
# Method <code>Rational#as_json</code> serializes `self`, returning a 2-element
|
|
1692
|
+
# hash representing `self`:
|
|
1676
1693
|
#
|
|
1677
1694
|
# require 'json/add/rational'
|
|
1678
1695
|
# x = Rational(2, 3).as_json
|
|
1679
1696
|
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
|
1680
1697
|
#
|
|
1681
|
-
# Method
|
|
1698
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Rational
|
|
1699
|
+
# object:
|
|
1682
1700
|
#
|
|
1683
1701
|
# Rational.json_create(x)
|
|
1684
1702
|
# # => (2/3)
|
|
@@ -1698,7 +1716,7 @@ class Rational
|
|
|
1698
1716
|
#
|
|
1699
1717
|
# {"json_class":"Rational","n":2,"d":3}
|
|
1700
1718
|
#
|
|
1701
|
-
def to_json: (?JSON::State state) -> String
|
|
1719
|
+
def to_json: (?JSON::State? state) -> String
|
|
1702
1720
|
end
|
|
1703
1721
|
|
|
1704
1722
|
%a{annotate:rdoc:skip}
|
|
@@ -1715,17 +1733,19 @@ class Regexp
|
|
|
1715
1733
|
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
|
1716
1734
|
# - as_json(*)
|
|
1717
1735
|
# -->
|
|
1718
|
-
# Methods
|
|
1719
|
-
# 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).
|
|
1720
1739
|
#
|
|
1721
|
-
# Method
|
|
1722
|
-
# representing `self`:
|
|
1740
|
+
# Method <code>Regexp#as_json</code> serializes `self`, returning a 2-element
|
|
1741
|
+
# hash representing `self`:
|
|
1723
1742
|
#
|
|
1724
1743
|
# require 'json/add/regexp'
|
|
1725
1744
|
# x = /foo/.as_json
|
|
1726
1745
|
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
|
1727
1746
|
#
|
|
1728
|
-
# Method
|
|
1747
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Regexp
|
|
1748
|
+
# object:
|
|
1729
1749
|
#
|
|
1730
1750
|
# Regexp.json_create(x) # => /foo/
|
|
1731
1751
|
#
|
|
@@ -1744,7 +1764,7 @@ class Regexp
|
|
|
1744
1764
|
#
|
|
1745
1765
|
# {"json_class":"Regexp","o":0,"s":"foo"}
|
|
1746
1766
|
#
|
|
1747
|
-
def to_json: (?JSON::State state) -> String
|
|
1767
|
+
def to_json: (?JSON::State? state) -> String
|
|
1748
1768
|
end
|
|
1749
1769
|
|
|
1750
1770
|
%a{annotate:rdoc:skip}
|
|
@@ -1761,17 +1781,18 @@ class Set[unchecked out A]
|
|
|
1761
1781
|
# rdoc-file=ext/json/lib/json/add/set.rb
|
|
1762
1782
|
# - as_json(*)
|
|
1763
1783
|
# -->
|
|
1764
|
-
# Methods
|
|
1765
|
-
# 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).
|
|
1766
1786
|
#
|
|
1767
|
-
# Method
|
|
1787
|
+
# Method <code>Set#as_json</code> serializes `self`, returning a 2-element hash
|
|
1768
1788
|
# representing `self`:
|
|
1769
1789
|
#
|
|
1770
1790
|
# require 'json/add/set'
|
|
1771
1791
|
# x = Set.new(%w/foo bar baz/).as_json
|
|
1772
1792
|
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
|
1773
1793
|
#
|
|
1774
|
-
# Method
|
|
1794
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Set
|
|
1795
|
+
# object:
|
|
1775
1796
|
#
|
|
1776
1797
|
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
|
1777
1798
|
#
|
|
@@ -1790,7 +1811,7 @@ class Set[unchecked out A]
|
|
|
1790
1811
|
#
|
|
1791
1812
|
# {"json_class":"Set","a":["foo","bar","baz"]}
|
|
1792
1813
|
#
|
|
1793
|
-
def to_json: (?JSON::State state) -> String
|
|
1814
|
+
def to_json: (?JSON::State? state) -> String
|
|
1794
1815
|
end
|
|
1795
1816
|
|
|
1796
1817
|
%a{annotate:rdoc:skip}
|
|
@@ -1807,18 +1828,20 @@ class Struct[Elem]
|
|
|
1807
1828
|
# rdoc-file=ext/json/lib/json/add/struct.rb
|
|
1808
1829
|
# - as_json(*)
|
|
1809
1830
|
# -->
|
|
1810
|
-
# Methods
|
|
1811
|
-
# 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).
|
|
1812
1834
|
#
|
|
1813
|
-
# Method
|
|
1814
|
-
# representing `self`:
|
|
1835
|
+
# Method <code>Struct#as_json</code> serializes `self`, returning a 2-element
|
|
1836
|
+
# hash representing `self`:
|
|
1815
1837
|
#
|
|
1816
1838
|
# require 'json/add/struct'
|
|
1817
1839
|
# Customer = Struct.new('Customer', :name, :address, :zip)
|
|
1818
1840
|
# x = Struct::Customer.new.as_json
|
|
1819
1841
|
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
|
1820
1842
|
#
|
|
1821
|
-
# Method
|
|
1843
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Struct
|
|
1844
|
+
# object:
|
|
1822
1845
|
#
|
|
1823
1846
|
# Struct::Customer.json_create(x)
|
|
1824
1847
|
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
|
@@ -1839,7 +1862,7 @@ class Struct[Elem]
|
|
|
1839
1862
|
#
|
|
1840
1863
|
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
|
1841
1864
|
#
|
|
1842
|
-
def to_json: (?JSON::State state) -> String
|
|
1865
|
+
def to_json: (?JSON::State? state) -> String
|
|
1843
1866
|
end
|
|
1844
1867
|
|
|
1845
1868
|
%a{annotate:rdoc:skip}
|
|
@@ -1856,17 +1879,19 @@ class Symbol
|
|
|
1856
1879
|
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
|
1857
1880
|
# - as_json(*)
|
|
1858
1881
|
# -->
|
|
1859
|
-
# Methods
|
|
1860
|
-
# 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).
|
|
1861
1885
|
#
|
|
1862
|
-
# Method
|
|
1863
|
-
# representing `self`:
|
|
1886
|
+
# Method <code>Symbol#as_json</code> serializes `self`, returning a 2-element
|
|
1887
|
+
# hash representing `self`:
|
|
1864
1888
|
#
|
|
1865
1889
|
# require 'json/add/symbol'
|
|
1866
1890
|
# x = :foo.as_json
|
|
1867
1891
|
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
|
1868
1892
|
#
|
|
1869
|
-
# Method
|
|
1893
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Symbol
|
|
1894
|
+
# object:
|
|
1870
1895
|
#
|
|
1871
1896
|
# Symbol.json_create(x) # => :foo
|
|
1872
1897
|
#
|
|
@@ -1885,7 +1910,7 @@ class Symbol
|
|
|
1885
1910
|
#
|
|
1886
1911
|
# # {"json_class":"Symbol","s":"foo"}
|
|
1887
1912
|
#
|
|
1888
|
-
def to_json: (?JSON::State state) -> String
|
|
1913
|
+
def to_json: (?JSON::State? state) -> String
|
|
1889
1914
|
end
|
|
1890
1915
|
|
|
1891
1916
|
%a{annotate:rdoc:skip}
|
|
@@ -1902,17 +1927,19 @@ class Time
|
|
|
1902
1927
|
# rdoc-file=ext/json/lib/json/add/time.rb
|
|
1903
1928
|
# - as_json(*)
|
|
1904
1929
|
# -->
|
|
1905
|
-
# Methods
|
|
1906
|
-
# 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).
|
|
1907
1933
|
#
|
|
1908
|
-
# Method
|
|
1934
|
+
# Method <code>Time#as_json</code> serializes `self`, returning a 2-element hash
|
|
1909
1935
|
# representing `self`:
|
|
1910
1936
|
#
|
|
1911
1937
|
# require 'json/add/time'
|
|
1912
1938
|
# x = Time.now.as_json
|
|
1913
1939
|
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
|
1914
1940
|
#
|
|
1915
|
-
# Method
|
|
1941
|
+
# Method <code>JSON.create</code> deserializes such a hash, returning a Time
|
|
1942
|
+
# object:
|
|
1916
1943
|
#
|
|
1917
1944
|
# Time.json_create(x)
|
|
1918
1945
|
# # => 2023-11-25 11:00:56.472846644 -0600
|
|
@@ -1932,5 +1959,5 @@ class Time
|
|
|
1932
1959
|
#
|
|
1933
1960
|
# {"json_class":"Time","s":1700931678,"n":980650786}
|
|
1934
1961
|
#
|
|
1935
|
-
def to_json: (?JSON::State state) -> String
|
|
1962
|
+
def to_json: (?JSON::State? state) -> String
|
|
1936
1963
|
end
|