rbs-relaxed 3.9.0.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 +7 -0
- data/.github/dependabot.yml +22 -0
- data/.github/workflows/comments.yml +35 -0
- data/.github/workflows/dependabot.yml +30 -0
- data/.github/workflows/ruby.yml +82 -0
- data/.github/workflows/typecheck.yml +38 -0
- data/.github/workflows/windows.yml +43 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +68 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +1868 -0
- data/COPYING +56 -0
- data/README.md +203 -0
- data/Rakefile +417 -0
- data/Steepfile +44 -0
- data/config.yml +313 -0
- data/core/array.rbs +4062 -0
- data/core/basic_object.rbs +375 -0
- data/core/binding.rbs +150 -0
- data/core/builtin.rbs +277 -0
- data/core/class.rbs +220 -0
- data/core/comparable.rbs +171 -0
- data/core/complex.rbs +786 -0
- data/core/constants.rbs +96 -0
- data/core/data.rbs +415 -0
- data/core/dir.rbs +981 -0
- data/core/encoding.rbs +1371 -0
- data/core/enumerable.rbs +2405 -0
- data/core/enumerator/product.rbs +92 -0
- data/core/enumerator.rbs +630 -0
- data/core/env.rbs +6 -0
- data/core/errno.rbs +673 -0
- data/core/errors.rbs +760 -0
- data/core/exception.rbs +485 -0
- data/core/false_class.rbs +82 -0
- data/core/fiber.rbs +550 -0
- data/core/fiber_error.rbs +11 -0
- data/core/file.rbs +2936 -0
- data/core/file_test.rbs +331 -0
- data/core/float.rbs +1151 -0
- data/core/gc.rbs +644 -0
- data/core/global_variables.rbs +184 -0
- data/core/hash.rbs +1861 -0
- data/core/integer.rbs +1413 -0
- data/core/io/buffer.rbs +984 -0
- data/core/io/wait.rbs +70 -0
- data/core/io.rbs +3406 -0
- data/core/kernel.rbs +3096 -0
- data/core/marshal.rbs +207 -0
- data/core/match_data.rbs +635 -0
- data/core/math.rbs +729 -0
- data/core/method.rbs +386 -0
- data/core/module.rbs +1704 -0
- data/core/nil_class.rbs +209 -0
- data/core/numeric.rbs +818 -0
- data/core/object.rbs +110 -0
- data/core/object_space/weak_key_map.rbs +166 -0
- data/core/object_space.rbs +190 -0
- data/core/proc.rbs +868 -0
- data/core/process.rbs +2296 -0
- data/core/ractor.rbs +1068 -0
- data/core/random.rbs +237 -0
- data/core/range.rbs +1107 -0
- data/core/rational.rbs +531 -0
- data/core/rb_config.rbs +88 -0
- data/core/rbs/unnamed/argf.rbs +1229 -0
- data/core/rbs/unnamed/env_class.rbs +1209 -0
- data/core/rbs/unnamed/random.rbs +293 -0
- data/core/refinement.rbs +59 -0
- data/core/regexp.rbs +1930 -0
- data/core/ruby_vm.rbs +765 -0
- data/core/rubygems/basic_specification.rbs +6 -0
- data/core/rubygems/config_file.rbs +38 -0
- data/core/rubygems/dependency_installer.rbs +6 -0
- data/core/rubygems/errors.rbs +176 -0
- data/core/rubygems/installer.rbs +15 -0
- data/core/rubygems/path_support.rbs +6 -0
- data/core/rubygems/platform.rbs +7 -0
- data/core/rubygems/request_set.rbs +49 -0
- data/core/rubygems/requirement.rbs +148 -0
- data/core/rubygems/rubygems.rbs +1171 -0
- data/core/rubygems/source_list.rbs +15 -0
- data/core/rubygems/specification.rbs +23 -0
- data/core/rubygems/stream_ui.rbs +5 -0
- data/core/rubygems/uninstaller.rbs +10 -0
- data/core/rubygems/version.rbs +294 -0
- data/core/set.rbs +621 -0
- data/core/signal.rbs +100 -0
- data/core/string.rbs +3583 -0
- data/core/struct.rbs +667 -0
- data/core/symbol.rbs +475 -0
- data/core/thread.rbs +1765 -0
- data/core/thread_group.rbs +79 -0
- data/core/time.rbs +1762 -0
- data/core/trace_point.rbs +477 -0
- data/core/true_class.rbs +98 -0
- data/core/unbound_method.rbs +329 -0
- data/core/warning.rbs +87 -0
- data/docs/CONTRIBUTING.md +106 -0
- data/docs/architecture.md +110 -0
- data/docs/collection.md +192 -0
- data/docs/data_and_struct.md +86 -0
- data/docs/gem.md +57 -0
- data/docs/rbs_by_example.md +309 -0
- data/docs/repo.md +125 -0
- data/docs/sigs.md +167 -0
- data/docs/stdlib.md +147 -0
- data/docs/syntax.md +910 -0
- data/docs/tools.md +17 -0
- data/exe/rbs +7 -0
- data/ext/rbs_extension/extconf.rb +15 -0
- data/ext/rbs_extension/lexer.c +2728 -0
- data/ext/rbs_extension/lexer.h +179 -0
- data/ext/rbs_extension/lexer.re +147 -0
- data/ext/rbs_extension/lexstate.c +175 -0
- data/ext/rbs_extension/location.c +325 -0
- data/ext/rbs_extension/location.h +85 -0
- data/ext/rbs_extension/main.c +33 -0
- data/ext/rbs_extension/parser.c +2973 -0
- data/ext/rbs_extension/parser.h +18 -0
- data/ext/rbs_extension/parserstate.c +397 -0
- data/ext/rbs_extension/parserstate.h +163 -0
- data/ext/rbs_extension/rbs_extension.h +31 -0
- data/ext/rbs_extension/unescape.c +32 -0
- data/goodcheck.yml +91 -0
- data/include/rbs/constants.h +82 -0
- data/include/rbs/ruby_objs.h +72 -0
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/include/rbs.h +7 -0
- data/lib/rbs/ancestor_graph.rb +92 -0
- data/lib/rbs/annotate/annotations.rb +199 -0
- data/lib/rbs/annotate/formatter.rb +92 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +400 -0
- data/lib/rbs/annotate/rdoc_source.rb +131 -0
- data/lib/rbs/annotate.rb +8 -0
- data/lib/rbs/ast/annotation.rb +29 -0
- data/lib/rbs/ast/comment.rb +29 -0
- data/lib/rbs/ast/declarations.rb +467 -0
- data/lib/rbs/ast/directives.rb +49 -0
- data/lib/rbs/ast/members.rb +451 -0
- data/lib/rbs/ast/type_param.rb +225 -0
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +67 -0
- data/lib/rbs/builtin_names.rb +58 -0
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +83 -0
- data/lib/rbs/cli/validate.rb +357 -0
- data/lib/rbs/cli.rb +1223 -0
- data/lib/rbs/collection/cleaner.rb +38 -0
- data/lib/rbs/collection/config/lockfile.rb +92 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +218 -0
- data/lib/rbs/collection/config.rb +81 -0
- data/lib/rbs/collection/installer.rb +32 -0
- data/lib/rbs/collection/sources/base.rb +14 -0
- data/lib/rbs/collection/sources/git.rb +258 -0
- data/lib/rbs/collection/sources/local.rb +81 -0
- data/lib/rbs/collection/sources/rubygems.rb +48 -0
- data/lib/rbs/collection/sources/stdlib.rb +50 -0
- data/lib/rbs/collection/sources.rb +38 -0
- data/lib/rbs/collection.rb +16 -0
- data/lib/rbs/constant.rb +28 -0
- data/lib/rbs/definition.rb +401 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +620 -0
- data/lib/rbs/definition_builder/method_builder.rb +254 -0
- data/lib/rbs/definition_builder.rb +845 -0
- data/lib/rbs/diff.rb +125 -0
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +829 -0
- data/lib/rbs/environment_loader.rb +173 -0
- data/lib/rbs/environment_walker.rb +155 -0
- data/lib/rbs/errors.rb +645 -0
- data/lib/rbs/factory.rb +18 -0
- data/lib/rbs/file_finder.rb +28 -0
- data/lib/rbs/location_aux.rb +138 -0
- data/lib/rbs/locator.rb +243 -0
- data/lib/rbs/method_type.rb +143 -0
- data/lib/rbs/namespace.rb +125 -0
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +114 -0
- data/lib/rbs/prototype/helpers.rb +140 -0
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +840 -0
- data/lib/rbs/prototype/rbi.rb +641 -0
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/reflection.rb +19 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
- data/lib/rbs/prototype/runtime.rb +667 -0
- data/lib/rbs/repository.rb +127 -0
- data/lib/rbs/resolver/constant_resolver.rb +219 -0
- data/lib/rbs/resolver/type_name_resolver.rb +91 -0
- data/lib/rbs/sorter.rb +198 -0
- data/lib/rbs/substitution.rb +83 -0
- data/lib/rbs/subtractor.rb +201 -0
- data/lib/rbs/test/errors.rb +80 -0
- data/lib/rbs/test/guaranteed.rb +30 -0
- data/lib/rbs/test/hook.rb +212 -0
- data/lib/rbs/test/observer.rb +19 -0
- data/lib/rbs/test/setup.rb +84 -0
- data/lib/rbs/test/setup_helper.rb +50 -0
- data/lib/rbs/test/tester.rb +167 -0
- data/lib/rbs/test/type_check.rb +435 -0
- data/lib/rbs/test.rb +112 -0
- data/lib/rbs/type_alias_dependency.rb +100 -0
- data/lib/rbs/type_alias_regularity.rb +126 -0
- data/lib/rbs/type_name.rb +109 -0
- data/lib/rbs/types.rb +1596 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +138 -0
- data/lib/rbs/unit_test/type_assertions.rb +347 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/validator.rb +186 -0
- data/lib/rbs/variance_calculator.rb +189 -0
- data/lib/rbs/vendorer.rb +71 -0
- data/lib/rbs/version.rb +5 -0
- data/lib/rbs/writer.rb +424 -0
- data/lib/rbs.rb +94 -0
- data/lib/rdoc/discover.rb +20 -0
- data/lib/rdoc_plugin/parser.rb +163 -0
- data/rbs-relaxed.gemspec +48 -0
- data/schema/annotation.json +14 -0
- data/schema/comment.json +26 -0
- data/schema/decls.json +326 -0
- data/schema/function.json +87 -0
- data/schema/location.json +56 -0
- data/schema/members.json +266 -0
- data/schema/methodType.json +50 -0
- data/schema/typeParam.json +36 -0
- data/schema/types.json +317 -0
- data/sig/ancestor_builder.rbs +163 -0
- data/sig/ancestor_graph.rbs +60 -0
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/annotation.rbs +27 -0
- data/sig/buffer.rbs +32 -0
- data/sig/builtin_names.rbs +44 -0
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +21 -0
- data/sig/cli/validate.rbs +43 -0
- data/sig/cli.rbs +87 -0
- data/sig/collection/cleaner.rbs +13 -0
- data/sig/collection/config/lockfile.rbs +74 -0
- data/sig/collection/config/lockfile_generator.rbs +66 -0
- data/sig/collection/config.rbs +46 -0
- data/sig/collection/installer.rbs +17 -0
- data/sig/collection/sources.rbs +214 -0
- data/sig/collection.rbs +4 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/declarations.rbs +267 -0
- data/sig/definition.rbs +173 -0
- data/sig/definition_builder.rbs +165 -0
- data/sig/diff.rbs +28 -0
- data/sig/directives.rbs +77 -0
- data/sig/environment.rbs +279 -0
- data/sig/environment_loader.rbs +111 -0
- data/sig/environment_walker.rbs +65 -0
- data/sig/errors.rbs +405 -0
- data/sig/factory.rbs +5 -0
- data/sig/file_finder.rbs +28 -0
- data/sig/location.rbs +110 -0
- data/sig/locator.rbs +58 -0
- data/sig/manifest.yaml +7 -0
- data/sig/members.rbs +258 -0
- data/sig/method_builder.rbs +84 -0
- data/sig/method_types.rbs +58 -0
- data/sig/namespace.rbs +146 -0
- data/sig/parser.rbs +100 -0
- data/sig/prototype/helpers.rbs +27 -0
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/prototype/rb.rbs +96 -0
- data/sig/prototype/rbi.rbs +75 -0
- data/sig/prototype/runtime.rbs +182 -0
- data/sig/rbs.rbs +21 -0
- data/sig/rdoc/rbs.rbs +67 -0
- data/sig/repository.rbs +85 -0
- data/sig/resolver/constant_resolver.rbs +92 -0
- data/sig/resolver/context.rbs +34 -0
- data/sig/resolver/type_name_resolver.rbs +35 -0
- data/sig/shims/bundler.rbs +38 -0
- data/sig/shims/enumerable.rbs +5 -0
- data/sig/shims/rubygems.rbs +19 -0
- data/sig/sorter.rbs +41 -0
- data/sig/substitution.rbs +48 -0
- data/sig/subtractor.rbs +37 -0
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/type_alias_dependency.rbs +53 -0
- data/sig/type_alias_regularity.rbs +98 -0
- data/sig/type_param.rbs +110 -0
- data/sig/typename.rbs +79 -0
- data/sig/types.rbs +579 -0
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +30 -0
- data/sig/unit_test/type_assertions.rbs +196 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/sig/use_map.rbs +35 -0
- data/sig/util.rbs +9 -0
- data/sig/validator.rbs +63 -0
- data/sig/variance_calculator.rbs +87 -0
- data/sig/vendorer.rbs +51 -0
- data/sig/version.rbs +3 -0
- data/sig/visitor.rbs +47 -0
- data/sig/writer.rbs +127 -0
- data/src/constants.c +153 -0
- data/src/ruby_objs.c +795 -0
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/abbrev/0/abbrev.rbs +66 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +355 -0
- data/stdlib/benchmark/0/benchmark.rbs +452 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +1629 -0
- data/stdlib/bigdecimal-math/0/big_math.rbs +119 -0
- data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
- data/stdlib/cgi/0/core.rbs +1285 -0
- data/stdlib/cgi/0/manifest.yaml +3 -0
- data/stdlib/coverage/0/coverage.rbs +263 -0
- data/stdlib/csv/0/csv.rbs +3776 -0
- data/stdlib/csv/0/manifest.yaml +3 -0
- data/stdlib/date/0/date.rbs +1585 -0
- data/stdlib/date/0/date_time.rbs +616 -0
- data/stdlib/date/0/time.rbs +26 -0
- data/stdlib/dbm/0/dbm.rbs +421 -0
- data/stdlib/delegate/0/delegator.rbs +184 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +96 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +343 -0
- data/stdlib/digest/0/digest.rbs +577 -0
- data/stdlib/erb/0/erb.rbs +532 -0
- data/stdlib/etc/0/etc.rbs +865 -0
- data/stdlib/fileutils/0/fileutils.rbs +1734 -0
- data/stdlib/find/0/find.rbs +49 -0
- data/stdlib/forwardable/0/forwardable.rbs +268 -0
- data/stdlib/io-console/0/io-console.rbs +414 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +428 -0
- data/stdlib/json/0/json.rbs +1916 -0
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/logger/0/formatter.rbs +45 -0
- data/stdlib/logger/0/log_device.rbs +100 -0
- data/stdlib/logger/0/logger.rbs +796 -0
- data/stdlib/logger/0/manifest.yaml +2 -0
- data/stdlib/logger/0/period.rbs +17 -0
- data/stdlib/logger/0/severity.rbs +34 -0
- data/stdlib/minitest/0/kernel.rbs +42 -0
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
- data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
- data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
- data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
- data/stdlib/minitest/0/minitest/compress.rbs +13 -0
- data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
- data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
- data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
- data/stdlib/minitest/0/minitest/guard.rbs +64 -0
- data/stdlib/minitest/0/minitest/mock.rbs +64 -0
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
- data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
- data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
- data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
- data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
- data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/result.rbs +28 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
- data/stdlib/minitest/0/minitest/skip.rbs +6 -0
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
- data/stdlib/minitest/0/minitest/spec.rbs +11 -0
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
- data/stdlib/minitest/0/minitest/test.rbs +69 -0
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
- data/stdlib/minitest/0/minitest/unit.rbs +4 -0
- data/stdlib/minitest/0/minitest.rbs +115 -0
- data/stdlib/monitor/0/monitor.rbs +363 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
- data/stdlib/net-http/0/manifest.yaml +3 -0
- data/stdlib/net-http/0/net-http.rbs +5552 -0
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/net-smtp/0/manifest.yaml +2 -0
- data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
- data/stdlib/nkf/0/nkf.rbs +402 -0
- data/stdlib/objspace/0/objspace.rbs +487 -0
- data/stdlib/observable/0/observable.rbs +217 -0
- data/stdlib/open-uri/0/manifest.yaml +4 -0
- data/stdlib/open-uri/0/open-uri.rbs +393 -0
- data/stdlib/open3/0/open3.rbs +147 -0
- data/stdlib/openssl/0/manifest.yaml +3 -0
- data/stdlib/openssl/0/openssl.rbs +12113 -0
- data/stdlib/optparse/0/optparse.rbs +1725 -0
- data/stdlib/pathname/0/pathname.rbs +1406 -0
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +300 -0
- data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
- data/stdlib/pstore/0/pstore.rbs +603 -0
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/psych/0/dbm.rbs +237 -0
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +402 -0
- data/stdlib/psych/0/store.rbs +59 -0
- data/stdlib/pty/0/pty.rbs +237 -0
- data/stdlib/rdoc/0/code_object.rbs +51 -0
- data/stdlib/rdoc/0/comment.rbs +59 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +117 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +391 -0
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/resolv/0/manifest.yaml +3 -0
- data/stdlib/resolv/0/resolv.rbs +1830 -0
- data/stdlib/ripper/0/ripper.rbs +1648 -0
- data/stdlib/securerandom/0/securerandom.rbs +62 -0
- data/stdlib/shellwords/0/shellwords.rbs +229 -0
- data/stdlib/singleton/0/singleton.rbs +131 -0
- data/stdlib/socket/0/addrinfo.rbs +666 -0
- data/stdlib/socket/0/basic_socket.rbs +590 -0
- data/stdlib/socket/0/constants.rbs +2295 -0
- data/stdlib/socket/0/ip_socket.rbs +92 -0
- data/stdlib/socket/0/socket.rbs +4157 -0
- data/stdlib/socket/0/socket_error.rbs +5 -0
- data/stdlib/socket/0/tcp_server.rbs +192 -0
- data/stdlib/socket/0/tcp_socket.rbs +79 -0
- data/stdlib/socket/0/udp_socket.rbs +133 -0
- data/stdlib/socket/0/unix_server.rbs +169 -0
- data/stdlib/socket/0/unix_socket.rbs +172 -0
- data/stdlib/stringio/0/stringio.rbs +567 -0
- data/stdlib/strscan/0/string_scanner.rbs +1627 -0
- data/stdlib/tempfile/0/tempfile.rbs +479 -0
- data/stdlib/time/0/time.rbs +432 -0
- data/stdlib/timeout/0/timeout.rbs +81 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
- data/stdlib/tsort/0/cyclic.rbs +5 -0
- data/stdlib/tsort/0/interfaces.rbs +20 -0
- data/stdlib/tsort/0/tsort.rbs +409 -0
- data/stdlib/uri/0/common.rbs +582 -0
- data/stdlib/uri/0/file.rbs +118 -0
- data/stdlib/uri/0/ftp.rbs +13 -0
- data/stdlib/uri/0/generic.rbs +1108 -0
- data/stdlib/uri/0/http.rbs +104 -0
- data/stdlib/uri/0/https.rbs +14 -0
- data/stdlib/uri/0/ldap.rbs +230 -0
- data/stdlib/uri/0/ldaps.rbs +14 -0
- data/stdlib/uri/0/mailto.rbs +92 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
- data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
- data/stdlib/uri/0/ws.rbs +13 -0
- data/stdlib/uri/0/wss.rbs +9 -0
- data/stdlib/yaml/0/manifest.yaml +2 -0
- data/stdlib/yaml/0/yaml.rbs +1 -0
- data/stdlib/zlib/0/buf_error.rbs +10 -0
- data/stdlib/zlib/0/data_error.rbs +10 -0
- data/stdlib/zlib/0/deflate.rbs +210 -0
- data/stdlib/zlib/0/error.rbs +20 -0
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
- data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
- data/stdlib/zlib/0/gzip_file.rbs +156 -0
- data/stdlib/zlib/0/gzip_reader.rbs +293 -0
- data/stdlib/zlib/0/gzip_writer.rbs +166 -0
- data/stdlib/zlib/0/inflate.rbs +180 -0
- data/stdlib/zlib/0/mem_error.rbs +10 -0
- data/stdlib/zlib/0/need_dict.rbs +13 -0
- data/stdlib/zlib/0/stream_end.rbs +11 -0
- data/stdlib/zlib/0/stream_error.rbs +11 -0
- data/stdlib/zlib/0/version_error.rbs +11 -0
- data/stdlib/zlib/0/zlib.rbs +449 -0
- data/stdlib/zlib/0/zstream.rbs +200 -0
- metadata +532 -0
@@ -0,0 +1,1916 @@
|
|
1
|
+
interface _ToJson
|
2
|
+
def to_json: (?JSON::State state) -> String
|
3
|
+
end
|
4
|
+
|
5
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
6
|
+
# The base exception for JSON errors.
|
7
|
+
#
|
8
|
+
class JSON::JSONError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
12
|
+
# This exception is raised if a generator or unparser error occurs.
|
13
|
+
#
|
14
|
+
class JSON::GeneratorError < JSON::JSONError
|
15
|
+
end
|
16
|
+
|
17
|
+
class JSON::UnparserError < JSON::GeneratorError
|
18
|
+
end
|
19
|
+
|
20
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
21
|
+
# This exception is raised if a parser error occurs.
|
22
|
+
#
|
23
|
+
class JSON::ParserError < JSON::JSONError
|
24
|
+
end
|
25
|
+
|
26
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
27
|
+
# This exception is raised if the nesting of parsed data structures is too deep.
|
28
|
+
#
|
29
|
+
class JSON::NestingError < JSON::ParserError
|
30
|
+
end
|
31
|
+
|
32
|
+
class JSON::State
|
33
|
+
end
|
34
|
+
|
35
|
+
# <!-- rdoc-file=ext/json/lib/json/ext.rb -->
|
36
|
+
# This module holds all the modules/classes that implement JSON's functionality
|
37
|
+
# as C extensions.
|
38
|
+
#
|
39
|
+
module JSON::Ext
|
40
|
+
end
|
41
|
+
|
42
|
+
# <!-- rdoc-file=ext/json/generator/generator.c -->
|
43
|
+
# This is the JSON generator implemented as a C extension. It can be configured
|
44
|
+
# to be used by setting
|
45
|
+
#
|
46
|
+
# JSON.generator = JSON::Ext::Generator
|
47
|
+
#
|
48
|
+
# with the method generator= in JSON.
|
49
|
+
#
|
50
|
+
module JSON::Ext::Generator
|
51
|
+
end
|
52
|
+
|
53
|
+
class JSON::Ext::Generator::State
|
54
|
+
end
|
55
|
+
|
56
|
+
# <!-- rdoc-file=ext/json/parser/parser.c -->
|
57
|
+
# This is the JSON parser implemented as a C extension. It can be configured to
|
58
|
+
# be used by setting
|
59
|
+
#
|
60
|
+
# JSON.parser = JSON::Ext::Parser
|
61
|
+
#
|
62
|
+
# with the method parser= in JSON.
|
63
|
+
#
|
64
|
+
class JSON::Ext::Parser
|
65
|
+
end
|
66
|
+
|
67
|
+
module JSON::Pure
|
68
|
+
end
|
69
|
+
|
70
|
+
module JSON::Pure::Generator
|
71
|
+
end
|
72
|
+
|
73
|
+
class JSON::Pure::Generator::State
|
74
|
+
end
|
75
|
+
|
76
|
+
class JSON::Pure::Parser
|
77
|
+
end
|
78
|
+
|
79
|
+
# <!-- rdoc-file=ext/json/lib/json.rb -->
|
80
|
+
# # JavaScript Object Notation (JSON)
|
81
|
+
#
|
82
|
+
# JSON is a lightweight data-interchange format.
|
83
|
+
#
|
84
|
+
# A JSON value is one of the following:
|
85
|
+
# * Double-quoted text: `"foo"`.
|
86
|
+
# * Number: `1`, `1.0`, `2.0e2`.
|
87
|
+
# * Boolean: `true`, `false`.
|
88
|
+
# * Null: `null`.
|
89
|
+
# * Array: an ordered list of values, enclosed by square brackets:
|
90
|
+
# ["foo", 1, 1.0, 2.0e2, true, false, null]
|
91
|
+
#
|
92
|
+
# * Object: a collection of name/value pairs, enclosed by curly braces; each
|
93
|
+
# name is double-quoted text; the values may be any JSON values:
|
94
|
+
# {"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}
|
95
|
+
#
|
96
|
+
# A JSON array or object may contain nested arrays, objects, and scalars to any
|
97
|
+
# depth:
|
98
|
+
# {"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}
|
99
|
+
# [{"foo": 0, "bar": 1}, ["baz", 2]]
|
100
|
+
#
|
101
|
+
# ## Using Module JSON
|
102
|
+
#
|
103
|
+
# To make module JSON available in your code, begin with:
|
104
|
+
# require 'json'
|
105
|
+
#
|
106
|
+
# All examples here assume that this has been done.
|
107
|
+
#
|
108
|
+
# ### Parsing JSON
|
109
|
+
#
|
110
|
+
# You can parse a String containing JSON data using either of two methods:
|
111
|
+
# * `JSON.parse(source, opts)`
|
112
|
+
# * `JSON.parse!(source, opts)`
|
113
|
+
#
|
114
|
+
# where
|
115
|
+
# * `source` is a Ruby object.
|
116
|
+
# * `opts` is a Hash object containing options that control both input allowed
|
117
|
+
# and output formatting.
|
118
|
+
#
|
119
|
+
# The difference between the two methods is that JSON.parse! omits some checks
|
120
|
+
# and may not be safe for some `source` data; use it only for data from trusted
|
121
|
+
# sources. Use the safer method JSON.parse for less trusted sources.
|
122
|
+
#
|
123
|
+
# #### Parsing JSON Arrays
|
124
|
+
#
|
125
|
+
# When `source` is a JSON array, JSON.parse by default returns a Ruby Array:
|
126
|
+
# json = '["foo", 1, 1.0, 2.0e2, true, false, null]'
|
127
|
+
# ruby = JSON.parse(json)
|
128
|
+
# ruby # => ["foo", 1, 1.0, 200.0, true, false, nil]
|
129
|
+
# ruby.class # => Array
|
130
|
+
#
|
131
|
+
# The JSON array may contain nested arrays, objects, and scalars to any depth:
|
132
|
+
# json = '[{"foo": 0, "bar": 1}, ["baz", 2]]'
|
133
|
+
# JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]]
|
134
|
+
#
|
135
|
+
# #### Parsing JSON Objects
|
136
|
+
#
|
137
|
+
# When the source is a JSON object, JSON.parse by default returns a Ruby Hash:
|
138
|
+
# json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}'
|
139
|
+
# ruby = JSON.parse(json)
|
140
|
+
# ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil}
|
141
|
+
# ruby.class # => Hash
|
142
|
+
#
|
143
|
+
# The JSON object may contain nested arrays, objects, and scalars to any depth:
|
144
|
+
# json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}'
|
145
|
+
# JSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]}
|
146
|
+
#
|
147
|
+
# #### Parsing JSON Scalars
|
148
|
+
#
|
149
|
+
# When the source is a JSON scalar (not an array or object), JSON.parse returns
|
150
|
+
# a Ruby scalar.
|
151
|
+
#
|
152
|
+
# String:
|
153
|
+
# ruby = JSON.parse('"foo"')
|
154
|
+
# ruby # => 'foo'
|
155
|
+
# ruby.class # => String
|
156
|
+
#
|
157
|
+
# Integer:
|
158
|
+
# ruby = JSON.parse('1')
|
159
|
+
# ruby # => 1
|
160
|
+
# ruby.class # => Integer
|
161
|
+
#
|
162
|
+
# Float:
|
163
|
+
# ruby = JSON.parse('1.0')
|
164
|
+
# ruby # => 1.0
|
165
|
+
# ruby.class # => Float
|
166
|
+
# ruby = JSON.parse('2.0e2')
|
167
|
+
# ruby # => 200
|
168
|
+
# ruby.class # => Float
|
169
|
+
#
|
170
|
+
# Boolean:
|
171
|
+
# ruby = JSON.parse('true')
|
172
|
+
# ruby # => true
|
173
|
+
# ruby.class # => TrueClass
|
174
|
+
# ruby = JSON.parse('false')
|
175
|
+
# ruby # => false
|
176
|
+
# ruby.class # => FalseClass
|
177
|
+
#
|
178
|
+
# Null:
|
179
|
+
# ruby = JSON.parse('null')
|
180
|
+
# ruby # => nil
|
181
|
+
# ruby.class # => NilClass
|
182
|
+
#
|
183
|
+
# #### Parsing Options
|
184
|
+
#
|
185
|
+
# ###### Input Options
|
186
|
+
#
|
187
|
+
# Option `max_nesting` (Integer) specifies the maximum nesting depth allowed;
|
188
|
+
# defaults to `100`; specify `false` to disable depth checking.
|
189
|
+
#
|
190
|
+
# With the default, `false`:
|
191
|
+
# source = '[0, [1, [2, [3]]]]'
|
192
|
+
# ruby = JSON.parse(source)
|
193
|
+
# ruby # => [0, [1, [2, [3]]]]
|
194
|
+
#
|
195
|
+
# Too deep:
|
196
|
+
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
197
|
+
# JSON.parse(source, {max_nesting: 1})
|
198
|
+
#
|
199
|
+
# Bad value:
|
200
|
+
# # Raises TypeError (wrong argument type Symbol (expected Fixnum)):
|
201
|
+
# JSON.parse(source, {max_nesting: :foo})
|
202
|
+
#
|
203
|
+
# ---
|
204
|
+
#
|
205
|
+
# Option `allow_nan` (boolean) specifies whether to allow NaN, Infinity, and
|
206
|
+
# MinusInfinity in `source`; defaults to `false`.
|
207
|
+
#
|
208
|
+
# With the default, `false`:
|
209
|
+
# # Raises JSON::ParserError (225: unexpected token at '[NaN]'):
|
210
|
+
# JSON.parse('[NaN]')
|
211
|
+
# # Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
|
212
|
+
# JSON.parse('[Infinity]')
|
213
|
+
# # Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
|
214
|
+
# JSON.parse('[-Infinity]')
|
215
|
+
#
|
216
|
+
# Allow:
|
217
|
+
# source = '[NaN, Infinity, -Infinity]'
|
218
|
+
# ruby = JSON.parse(source, {allow_nan: true})
|
219
|
+
# ruby # => [NaN, Infinity, -Infinity]
|
220
|
+
#
|
221
|
+
# ###### Output Options
|
222
|
+
#
|
223
|
+
# Option `symbolize_names` (boolean) specifies whether returned Hash keys should
|
224
|
+
# be Symbols; defaults to `false` (use Strings).
|
225
|
+
#
|
226
|
+
# With the default, `false`:
|
227
|
+
# source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
|
228
|
+
# ruby = JSON.parse(source)
|
229
|
+
# ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
|
230
|
+
#
|
231
|
+
# Use Symbols:
|
232
|
+
# ruby = JSON.parse(source, {symbolize_names: true})
|
233
|
+
# ruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
|
234
|
+
#
|
235
|
+
# ---
|
236
|
+
#
|
237
|
+
# Option `object_class` (Class) specifies the Ruby class to be used for each
|
238
|
+
# JSON object; defaults to Hash.
|
239
|
+
#
|
240
|
+
# With the default, Hash:
|
241
|
+
# source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
|
242
|
+
# ruby = JSON.parse(source)
|
243
|
+
# ruby.class # => Hash
|
244
|
+
#
|
245
|
+
# Use class OpenStruct:
|
246
|
+
# ruby = JSON.parse(source, {object_class: OpenStruct})
|
247
|
+
# ruby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
|
248
|
+
#
|
249
|
+
# ---
|
250
|
+
#
|
251
|
+
# Option `array_class` (Class) specifies the Ruby class to be used for each JSON
|
252
|
+
# array; defaults to Array.
|
253
|
+
#
|
254
|
+
# With the default, Array:
|
255
|
+
# source = '["foo", 1.0, true, false, null]'
|
256
|
+
# ruby = JSON.parse(source)
|
257
|
+
# ruby.class # => Array
|
258
|
+
#
|
259
|
+
# Use class Set:
|
260
|
+
# ruby = JSON.parse(source, {array_class: Set})
|
261
|
+
# ruby # => #<Set: {"foo", 1.0, true, false, nil}>
|
262
|
+
#
|
263
|
+
# ---
|
264
|
+
#
|
265
|
+
# Option `create_additions` (boolean) specifies whether to use JSON additions in
|
266
|
+
# parsing. See [\JSON Additions](#module-JSON-label-JSON+Additions).
|
267
|
+
#
|
268
|
+
# ### Generating JSON
|
269
|
+
#
|
270
|
+
# To generate a Ruby String containing JSON data, use method
|
271
|
+
# `JSON.generate(source, opts)`, where
|
272
|
+
# * `source` is a Ruby object.
|
273
|
+
# * `opts` is a Hash object containing options that control both input allowed
|
274
|
+
# and output formatting.
|
275
|
+
#
|
276
|
+
# #### Generating JSON from Arrays
|
277
|
+
#
|
278
|
+
# When the source is a Ruby Array, JSON.generate returns a String containing a
|
279
|
+
# JSON array:
|
280
|
+
# ruby = [0, 's', :foo]
|
281
|
+
# json = JSON.generate(ruby)
|
282
|
+
# json # => '[0,"s","foo"]'
|
283
|
+
#
|
284
|
+
# The Ruby Array array may contain nested arrays, hashes, and scalars to any
|
285
|
+
# depth:
|
286
|
+
# ruby = [0, [1, 2], {foo: 3, bar: 4}]
|
287
|
+
# json = JSON.generate(ruby)
|
288
|
+
# json # => '[0,[1,2],{"foo":3,"bar":4}]'
|
289
|
+
#
|
290
|
+
# #### Generating JSON from Hashes
|
291
|
+
#
|
292
|
+
# When the source is a Ruby Hash, JSON.generate returns a String containing a
|
293
|
+
# JSON object:
|
294
|
+
# ruby = {foo: 0, bar: 's', baz: :bat}
|
295
|
+
# json = JSON.generate(ruby)
|
296
|
+
# json # => '{"foo":0,"bar":"s","baz":"bat"}'
|
297
|
+
#
|
298
|
+
# The Ruby Hash array may contain nested arrays, hashes, and scalars to any
|
299
|
+
# depth:
|
300
|
+
# ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
|
301
|
+
# json = JSON.generate(ruby)
|
302
|
+
# json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
|
303
|
+
#
|
304
|
+
# #### Generating JSON from Other Objects
|
305
|
+
#
|
306
|
+
# When the source is neither an Array nor a Hash, the generated JSON data
|
307
|
+
# depends on the class of the source.
|
308
|
+
#
|
309
|
+
# When the source is a Ruby Integer or Float, JSON.generate returns a String
|
310
|
+
# containing a JSON number:
|
311
|
+
# JSON.generate(42) # => '42'
|
312
|
+
# JSON.generate(0.42) # => '0.42'
|
313
|
+
#
|
314
|
+
# When the source is a Ruby String, JSON.generate returns a String containing a
|
315
|
+
# JSON string (with double-quotes):
|
316
|
+
# JSON.generate('A string') # => '"A string"'
|
317
|
+
#
|
318
|
+
# When the source is `true`, `false` or `nil`, JSON.generate returns a String
|
319
|
+
# containing the corresponding JSON token:
|
320
|
+
# JSON.generate(true) # => 'true'
|
321
|
+
# JSON.generate(false) # => 'false'
|
322
|
+
# JSON.generate(nil) # => 'null'
|
323
|
+
#
|
324
|
+
# When the source is none of the above, JSON.generate returns a String
|
325
|
+
# containing a JSON string representation of the source:
|
326
|
+
# JSON.generate(:foo) # => '"foo"'
|
327
|
+
# JSON.generate(Complex(0, 0)) # => '"0+0i"'
|
328
|
+
# JSON.generate(Dir.new('.')) # => '"#<Dir>"'
|
329
|
+
#
|
330
|
+
# #### Generating Options
|
331
|
+
#
|
332
|
+
# ###### Input Options
|
333
|
+
#
|
334
|
+
# Option `allow_nan` (boolean) specifies whether `NaN`, `Infinity`, and
|
335
|
+
# `-Infinity` may be generated; defaults to `false`.
|
336
|
+
#
|
337
|
+
# With the default, `false`:
|
338
|
+
# # Raises JSON::GeneratorError (920: NaN not allowed in JSON):
|
339
|
+
# JSON.generate(JSON::NaN)
|
340
|
+
# # Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
|
341
|
+
# JSON.generate(JSON::Infinity)
|
342
|
+
# # Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
|
343
|
+
# JSON.generate(JSON::MinusInfinity)
|
344
|
+
#
|
345
|
+
# Allow:
|
346
|
+
# ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
|
347
|
+
# JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
|
348
|
+
#
|
349
|
+
# ---
|
350
|
+
#
|
351
|
+
# Option `max_nesting` (Integer) specifies the maximum nesting depth in `obj`;
|
352
|
+
# defaults to `100`.
|
353
|
+
#
|
354
|
+
# With the default, `100`:
|
355
|
+
# obj = [[[[[[0]]]]]]
|
356
|
+
# JSON.generate(obj) # => '[[[[[[0]]]]]]'
|
357
|
+
#
|
358
|
+
# Too deep:
|
359
|
+
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
360
|
+
# JSON.generate(obj, max_nesting: 2)
|
361
|
+
#
|
362
|
+
# ###### Escaping Options
|
363
|
+
#
|
364
|
+
# Options `script_safe` (boolean) specifies wether `'\u2028'`, `'\u2029'` and
|
365
|
+
# `'/'` should be escaped as to make the JSON object safe to interpolate in
|
366
|
+
# script tags.
|
367
|
+
#
|
368
|
+
# Options `ascii_only` (boolean) specifies wether all characters outside the
|
369
|
+
# ASCII range should be escaped.
|
370
|
+
#
|
371
|
+
# ###### Output Options
|
372
|
+
#
|
373
|
+
# The default formatting options generate the most compact JSON data, all on one
|
374
|
+
# line and with no whitespace.
|
375
|
+
#
|
376
|
+
# You can use these formatting options to generate JSON data in a more open
|
377
|
+
# format, using whitespace. See also JSON.pretty_generate.
|
378
|
+
#
|
379
|
+
# * Option `array_nl` (String) specifies a string (usually a newline) to be
|
380
|
+
# inserted after each JSON array; defaults to the empty String, `''`.
|
381
|
+
# * Option `object_nl` (String) specifies a string (usually a newline) to be
|
382
|
+
# inserted after each JSON object; defaults to the empty String, `''`.
|
383
|
+
# * Option `indent` (String) specifies the string (usually spaces) to be used
|
384
|
+
# for indentation; defaults to the empty String, `''`; defaults to the empty
|
385
|
+
# String, `''`; has no effect unless options `array_nl` or `object_nl`
|
386
|
+
# specify newlines.
|
387
|
+
# * Option `space` (String) specifies a string (usually a space) to be
|
388
|
+
# inserted after the colon in each JSON object's pair; defaults to the empty
|
389
|
+
# String, `''`.
|
390
|
+
# * Option `space_before` (String) specifies a string (usually a space) to be
|
391
|
+
# inserted before the colon in each JSON object's pair; defaults to the
|
392
|
+
# empty String, `''`.
|
393
|
+
#
|
394
|
+
# In this example, `obj` is used first to generate the shortest JSON data (no
|
395
|
+
# whitespace), then again with all formatting options specified:
|
396
|
+
#
|
397
|
+
# obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
|
398
|
+
# json = JSON.generate(obj)
|
399
|
+
# puts 'Compact:', json
|
400
|
+
# opts = {
|
401
|
+
# array_nl: "\n",
|
402
|
+
# object_nl: "\n",
|
403
|
+
# indent: ' ',
|
404
|
+
# space_before: ' ',
|
405
|
+
# space: ' '
|
406
|
+
# }
|
407
|
+
# puts 'Open:', JSON.generate(obj, opts)
|
408
|
+
#
|
409
|
+
# Output:
|
410
|
+
# Compact:
|
411
|
+
# {"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
|
412
|
+
# Open:
|
413
|
+
# {
|
414
|
+
# "foo" : [
|
415
|
+
# "bar",
|
416
|
+
# "baz"
|
417
|
+
# ],
|
418
|
+
# "bat" : {
|
419
|
+
# "bam" : 0,
|
420
|
+
# "bad" : 1
|
421
|
+
# }
|
422
|
+
# }
|
423
|
+
#
|
424
|
+
# ## JSON Additions
|
425
|
+
#
|
426
|
+
# When you "round trip" a non-String object from Ruby to JSON and back, you have
|
427
|
+
# a new String, instead of the object you began with:
|
428
|
+
# ruby0 = Range.new(0, 2)
|
429
|
+
# json = JSON.generate(ruby0)
|
430
|
+
# json # => '0..2"'
|
431
|
+
# ruby1 = JSON.parse(json)
|
432
|
+
# ruby1 # => '0..2'
|
433
|
+
# ruby1.class # => String
|
434
|
+
#
|
435
|
+
# You can use JSON *additions* to preserve the original object. The addition is
|
436
|
+
# an extension of a ruby class, so that:
|
437
|
+
# * JSON.generate stores more information in the JSON string.
|
438
|
+
# * JSON.parse, called with option `create_additions`, uses that information
|
439
|
+
# to create a proper Ruby object.
|
440
|
+
#
|
441
|
+
# This example shows a Range being generated into JSON and parsed back into
|
442
|
+
# Ruby, both without and with the addition for Range:
|
443
|
+
# ruby = Range.new(0, 2)
|
444
|
+
# # This passage does not use the addition for Range.
|
445
|
+
# json0 = JSON.generate(ruby)
|
446
|
+
# ruby0 = JSON.parse(json0)
|
447
|
+
# # This passage uses the addition for Range.
|
448
|
+
# require 'json/add/range'
|
449
|
+
# json1 = JSON.generate(ruby)
|
450
|
+
# ruby1 = JSON.parse(json1, create_additions: true)
|
451
|
+
# # Make a nice display.
|
452
|
+
# display = <<~EOT
|
453
|
+
# Generated JSON:
|
454
|
+
# Without addition: #{json0} (#{json0.class})
|
455
|
+
# With addition: #{json1} (#{json1.class})
|
456
|
+
# Parsed JSON:
|
457
|
+
# Without addition: #{ruby0.inspect} (#{ruby0.class})
|
458
|
+
# With addition: #{ruby1.inspect} (#{ruby1.class})
|
459
|
+
# EOT
|
460
|
+
# puts display
|
461
|
+
#
|
462
|
+
# This output shows the different results:
|
463
|
+
# Generated JSON:
|
464
|
+
# Without addition: "0..2" (String)
|
465
|
+
# With addition: {"json_class":"Range","a":[0,2,false]} (String)
|
466
|
+
# Parsed JSON:
|
467
|
+
# Without addition: "0..2" (String)
|
468
|
+
# With addition: 0..2 (Range)
|
469
|
+
#
|
470
|
+
# The JSON module includes additions for certain classes. You can also craft
|
471
|
+
# custom additions. See [Custom \JSON
|
472
|
+
# Additions](#module-JSON-label-Custom+JSON+Additions).
|
473
|
+
#
|
474
|
+
# ### Built-in Additions
|
475
|
+
#
|
476
|
+
# The JSON module includes additions for certain classes. To use an addition,
|
477
|
+
# `require` its source:
|
478
|
+
# * BigDecimal: `require 'json/add/bigdecimal'`
|
479
|
+
# * Complex: `require 'json/add/complex'`
|
480
|
+
# * Date: `require 'json/add/date'`
|
481
|
+
# * DateTime: `require 'json/add/date_time'`
|
482
|
+
# * Exception: `require 'json/add/exception'`
|
483
|
+
# * OpenStruct: `require 'json/add/ostruct'`
|
484
|
+
# * Range: `require 'json/add/range'`
|
485
|
+
# * Rational: `require 'json/add/rational'`
|
486
|
+
# * Regexp: `require 'json/add/regexp'`
|
487
|
+
# * Set: `require 'json/add/set'`
|
488
|
+
# * Struct: `require 'json/add/struct'`
|
489
|
+
# * Symbol: `require 'json/add/symbol'`
|
490
|
+
# * Time: `require 'json/add/time'`
|
491
|
+
#
|
492
|
+
# To reduce punctuation clutter, the examples below show the generated JSON via
|
493
|
+
# `puts`, rather than the usual `inspect`,
|
494
|
+
#
|
495
|
+
# BigDecimal:
|
496
|
+
# require 'json/add/bigdecimal'
|
497
|
+
# ruby0 = BigDecimal(0) # 0.0
|
498
|
+
# json = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"}
|
499
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 0.0
|
500
|
+
# ruby1.class # => BigDecimal
|
501
|
+
#
|
502
|
+
# Complex:
|
503
|
+
# require 'json/add/complex'
|
504
|
+
# ruby0 = Complex(1+0i) # 1+0i
|
505
|
+
# json = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0}
|
506
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 1+0i
|
507
|
+
# ruby1.class # Complex
|
508
|
+
#
|
509
|
+
# Date:
|
510
|
+
# require 'json/add/date'
|
511
|
+
# ruby0 = Date.today # 2020-05-02
|
512
|
+
# json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0}
|
513
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02
|
514
|
+
# ruby1.class # Date
|
515
|
+
#
|
516
|
+
# DateTime:
|
517
|
+
# require 'json/add/date_time'
|
518
|
+
# ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00
|
519
|
+
# json = JSON.generate(ruby0) # {"json_class":"DateTime","y":2020,"m":5,"d":2,"H":10,"M":38,"S":13,"of":"-5/24","sg":2299161.0}
|
520
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00
|
521
|
+
# ruby1.class # DateTime
|
522
|
+
#
|
523
|
+
# Exception (and its subclasses including RuntimeError):
|
524
|
+
# require 'json/add/exception'
|
525
|
+
# ruby0 = Exception.new('A message') # A message
|
526
|
+
# json = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null}
|
527
|
+
# ruby1 = JSON.parse(json, create_additions: true) # A message
|
528
|
+
# ruby1.class # Exception
|
529
|
+
# ruby0 = RuntimeError.new('Another message') # Another message
|
530
|
+
# json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null}
|
531
|
+
# ruby1 = JSON.parse(json, create_additions: true) # Another message
|
532
|
+
# ruby1.class # RuntimeError
|
533
|
+
#
|
534
|
+
# OpenStruct:
|
535
|
+
# require 'json/add/ostruct'
|
536
|
+
# ruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby">
|
537
|
+
# json = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}}
|
538
|
+
# ruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby">
|
539
|
+
# ruby1.class # OpenStruct
|
540
|
+
#
|
541
|
+
# Range:
|
542
|
+
# require 'json/add/range'
|
543
|
+
# ruby0 = Range.new(0, 2) # 0..2
|
544
|
+
# json = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]}
|
545
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 0..2
|
546
|
+
# ruby1.class # Range
|
547
|
+
#
|
548
|
+
# Rational:
|
549
|
+
# require 'json/add/rational'
|
550
|
+
# ruby0 = Rational(1, 3) # 1/3
|
551
|
+
# json = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3}
|
552
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 1/3
|
553
|
+
# ruby1.class # Rational
|
554
|
+
#
|
555
|
+
# Regexp:
|
556
|
+
# require 'json/add/regexp'
|
557
|
+
# ruby0 = Regexp.new('foo') # (?-mix:foo)
|
558
|
+
# json = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"}
|
559
|
+
# ruby1 = JSON.parse(json, create_additions: true) # (?-mix:foo)
|
560
|
+
# ruby1.class # Regexp
|
561
|
+
#
|
562
|
+
# Set:
|
563
|
+
# require 'json/add/set'
|
564
|
+
# ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}>
|
565
|
+
# json = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]}
|
566
|
+
# ruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}>
|
567
|
+
# ruby1.class # Set
|
568
|
+
#
|
569
|
+
# Struct:
|
570
|
+
# require 'json/add/struct'
|
571
|
+
# Customer = Struct.new(:name, :address) # Customer
|
572
|
+
# ruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main">
|
573
|
+
# json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
|
574
|
+
# ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
|
575
|
+
# ruby1.class # Customer
|
576
|
+
#
|
577
|
+
# Symbol:
|
578
|
+
# require 'json/add/symbol'
|
579
|
+
# ruby0 = :foo # foo
|
580
|
+
# json = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"}
|
581
|
+
# ruby1 = JSON.parse(json, create_additions: true) # foo
|
582
|
+
# ruby1.class # Symbol
|
583
|
+
#
|
584
|
+
# Time:
|
585
|
+
# require 'json/add/time'
|
586
|
+
# ruby0 = Time.now # 2020-05-02 11:28:26 -0500
|
587
|
+
# json = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000}
|
588
|
+
# ruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500
|
589
|
+
# ruby1.class # Time
|
590
|
+
#
|
591
|
+
# ### Custom JSON Additions
|
592
|
+
#
|
593
|
+
# In addition to the JSON additions provided, you can craft JSON additions of
|
594
|
+
# your own, either for Ruby built-in classes or for user-defined classes.
|
595
|
+
#
|
596
|
+
# Here's a user-defined class `Foo`:
|
597
|
+
# class Foo
|
598
|
+
# attr_accessor :bar, :baz
|
599
|
+
# def initialize(bar, baz)
|
600
|
+
# self.bar = bar
|
601
|
+
# self.baz = baz
|
602
|
+
# end
|
603
|
+
# end
|
604
|
+
#
|
605
|
+
# Here's the JSON addition for it:
|
606
|
+
# # Extend class Foo with JSON addition.
|
607
|
+
# class Foo
|
608
|
+
# # Serialize Foo object with its class name and arguments
|
609
|
+
# def to_json(*args)
|
610
|
+
# {
|
611
|
+
# JSON.create_id => self.class.name,
|
612
|
+
# 'a' => [ bar, baz ]
|
613
|
+
# }.to_json(*args)
|
614
|
+
# end
|
615
|
+
# # Deserialize JSON string by constructing new Foo object with arguments.
|
616
|
+
# def self.json_create(object)
|
617
|
+
# new(*object['a'])
|
618
|
+
# end
|
619
|
+
# end
|
620
|
+
#
|
621
|
+
# Demonstration:
|
622
|
+
# require 'json'
|
623
|
+
# # This Foo object has no custom addition.
|
624
|
+
# foo0 = Foo.new(0, 1)
|
625
|
+
# json0 = JSON.generate(foo0)
|
626
|
+
# obj0 = JSON.parse(json0)
|
627
|
+
# # Lood the custom addition.
|
628
|
+
# require_relative 'foo_addition'
|
629
|
+
# # This foo has the custom addition.
|
630
|
+
# foo1 = Foo.new(0, 1)
|
631
|
+
# json1 = JSON.generate(foo1)
|
632
|
+
# obj1 = JSON.parse(json1, create_additions: true)
|
633
|
+
# # Make a nice display.
|
634
|
+
# display = <<~EOT
|
635
|
+
# Generated JSON:
|
636
|
+
# Without custom addition: #{json0} (#{json0.class})
|
637
|
+
# With custom addition: #{json1} (#{json1.class})
|
638
|
+
# Parsed JSON:
|
639
|
+
# Without custom addition: #{obj0.inspect} (#{obj0.class})
|
640
|
+
# With custom addition: #{obj1.inspect} (#{obj1.class})
|
641
|
+
# EOT
|
642
|
+
# puts display
|
643
|
+
#
|
644
|
+
# Output:
|
645
|
+
#
|
646
|
+
# Generated JSON:
|
647
|
+
# Without custom addition: "#<Foo:0x0000000006534e80>" (String)
|
648
|
+
# With custom addition: {"json_class":"Foo","a":[0,1]} (String)
|
649
|
+
# Parsed JSON:
|
650
|
+
# Without custom addition: "#<Foo:0x0000000006534e80>" (String)
|
651
|
+
# With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo)
|
652
|
+
#
|
653
|
+
module JSON
|
654
|
+
type options = Hash[Symbol, untyped]
|
655
|
+
|
656
|
+
type generator = singleton(::JSON::Ext::Generator) | singleton(::JSON::Pure::Generator)
|
657
|
+
|
658
|
+
type parser = singleton(::JSON::Ext::Parser) | singleton(::JSON::Pure::Parser)
|
659
|
+
|
660
|
+
type state = singleton(JSON::Ext::Generator::State) | singleton(JSON::Pure::Generator::State)
|
661
|
+
|
662
|
+
interface _WritableIO
|
663
|
+
def to_io: () -> _Write
|
664
|
+
end
|
665
|
+
|
666
|
+
interface _Write
|
667
|
+
def write: (String json) -> void
|
668
|
+
|
669
|
+
def flush: () -> void
|
670
|
+
end
|
671
|
+
|
672
|
+
interface _ReadableIO
|
673
|
+
def to_io: () -> _Read
|
674
|
+
end
|
675
|
+
|
676
|
+
interface _Read
|
677
|
+
def read: () -> string
|
678
|
+
end
|
679
|
+
|
680
|
+
# <!--
|
681
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
682
|
+
# - JSON[object] -> new_array or new_string
|
683
|
+
# -->
|
684
|
+
# If `object` is a String, calls JSON.parse with `object` and `opts` (see method
|
685
|
+
# #parse):
|
686
|
+
# json = '[0, 1, null]'
|
687
|
+
# JSON[json]# => [0, 1, nil]
|
688
|
+
#
|
689
|
+
# Otherwise, calls JSON.generate with `object` and `opts` (see method
|
690
|
+
# #generate):
|
691
|
+
# ruby = [0, 1, nil]
|
692
|
+
# JSON[ruby] # => '[0,1,null]'
|
693
|
+
#
|
694
|
+
def self.[]: (untyped object, ?options opts) -> untyped
|
695
|
+
|
696
|
+
# <!--
|
697
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
698
|
+
# - create_id()
|
699
|
+
# -->
|
700
|
+
# Returns the current create identifier. See also JSON.create_id=.
|
701
|
+
#
|
702
|
+
def self.create_id: () -> _ToS
|
703
|
+
|
704
|
+
# <!--
|
705
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
706
|
+
# - create_id=(new_value)
|
707
|
+
# -->
|
708
|
+
# Sets create identifier, which is used to decide if the *json_create* hook of a
|
709
|
+
# class should be called; initial value is `json_class`:
|
710
|
+
# JSON.create_id # => 'json_class'
|
711
|
+
#
|
712
|
+
def self.create_id=: (_ToS create_id) -> _ToS
|
713
|
+
|
714
|
+
def self.deep_const_get: (interned path) -> untyped
|
715
|
+
|
716
|
+
# <!--
|
717
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
718
|
+
# - JSON.dump(obj, io = nil, limit = nil)
|
719
|
+
# -->
|
720
|
+
# Dumps `obj` as a JSON string, i.e. calls generate on the object and returns
|
721
|
+
# the result.
|
722
|
+
#
|
723
|
+
# The default options can be changed via method JSON.dump_default_options.
|
724
|
+
#
|
725
|
+
# * Argument `io`, if given, should respond to method `write`; the JSON String
|
726
|
+
# is written to `io`, and `io` is returned. If `io` is not given, the JSON
|
727
|
+
# String is returned.
|
728
|
+
# * Argument `limit`, if given, is passed to JSON.generate as option
|
729
|
+
# `max_nesting`.
|
730
|
+
#
|
731
|
+
# ---
|
732
|
+
#
|
733
|
+
# When argument `io` is not given, returns the JSON String generated from `obj`:
|
734
|
+
# obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
|
735
|
+
# json = JSON.dump(obj)
|
736
|
+
# json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
|
737
|
+
#
|
738
|
+
# When argument `io` is given, writes the JSON String to `io` and returns `io`:
|
739
|
+
# path = 't.json'
|
740
|
+
# File.open(path, 'w') do |file|
|
741
|
+
# JSON.dump(obj, file)
|
742
|
+
# end # => #<File:t.json (closed)>
|
743
|
+
# puts File.read(path)
|
744
|
+
#
|
745
|
+
# Output:
|
746
|
+
# {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
|
747
|
+
#
|
748
|
+
def self?.dump: (_ToJson obj, ?Integer limit) -> String
|
749
|
+
| (_ToJson obj, _WritableIO anIO) -> _Write
|
750
|
+
| (_ToJson obj, _Write anIO, ?Integer limit) -> _Write
|
751
|
+
|
752
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
753
|
+
# Sets or returns the default options for the JSON.dump method. Initially:
|
754
|
+
# opts = JSON.dump_default_options
|
755
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
756
|
+
#
|
757
|
+
def self.dump_default_options: () -> options
|
758
|
+
|
759
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
760
|
+
# Sets or returns the default options for the JSON.dump method. Initially:
|
761
|
+
# opts = JSON.dump_default_options
|
762
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true}
|
763
|
+
#
|
764
|
+
def self.dump_default_options=: (options) -> options
|
765
|
+
|
766
|
+
# <!--
|
767
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
768
|
+
# - JSON.fast_generate(obj, opts) -> new_string
|
769
|
+
# -->
|
770
|
+
# Arguments `obj` and `opts` here are the same as arguments `obj` and `opts` in
|
771
|
+
# JSON.generate.
|
772
|
+
#
|
773
|
+
# By default, generates JSON data without checking for circular references in
|
774
|
+
# `obj` (option `max_nesting` set to `false`, disabled).
|
775
|
+
#
|
776
|
+
# Raises an exception if `obj` contains circular references:
|
777
|
+
# a = []; b = []; a.push(b); b.push(a)
|
778
|
+
# # Raises SystemStackError (stack level too deep):
|
779
|
+
# JSON.fast_generate(a)
|
780
|
+
#
|
781
|
+
def self?.fast_generate: (_ToJson obj, ?options opts) -> String
|
782
|
+
|
783
|
+
alias self.fast_unparse self.fast_generate
|
784
|
+
|
785
|
+
alias fast_unparse fast_generate
|
786
|
+
|
787
|
+
# <!--
|
788
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
789
|
+
# - JSON.generate(obj, opts = nil) -> new_string
|
790
|
+
# -->
|
791
|
+
# Returns a String containing the generated JSON data.
|
792
|
+
#
|
793
|
+
# See also JSON.fast_generate, JSON.pretty_generate.
|
794
|
+
#
|
795
|
+
# Argument `obj` is the Ruby object to be converted to JSON.
|
796
|
+
#
|
797
|
+
# Argument `opts`, if given, contains a Hash of options for the generation. See
|
798
|
+
# [Generating Options](#module-JSON-label-Generating+Options).
|
799
|
+
#
|
800
|
+
# ---
|
801
|
+
#
|
802
|
+
# When `obj` is an Array, returns a String containing a JSON array:
|
803
|
+
# obj = ["foo", 1.0, true, false, nil]
|
804
|
+
# json = JSON.generate(obj)
|
805
|
+
# json # => '["foo",1.0,true,false,null]'
|
806
|
+
#
|
807
|
+
# When `obj` is a Hash, returns a String containing a JSON object:
|
808
|
+
# obj = {foo: 0, bar: 's', baz: :bat}
|
809
|
+
# json = JSON.generate(obj)
|
810
|
+
# json # => '{"foo":0,"bar":"s","baz":"bat"}'
|
811
|
+
#
|
812
|
+
# For examples of generating from other Ruby objects, see [Generating \JSON from
|
813
|
+
# Other Objects](#module-JSON-label-Generating+JSON+from+Other+Objects).
|
814
|
+
#
|
815
|
+
# ---
|
816
|
+
#
|
817
|
+
# Raises an exception if any formatting option is not a String.
|
818
|
+
#
|
819
|
+
# Raises an exception if `obj` contains circular references:
|
820
|
+
# a = []; b = []; a.push(b); b.push(a)
|
821
|
+
# # Raises JSON::NestingError (nesting of 100 is too deep):
|
822
|
+
# JSON.generate(a)
|
823
|
+
#
|
824
|
+
def self?.generate: (_ToJson obj, ?options opts) -> String
|
825
|
+
|
826
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
827
|
+
# Returns the JSON generator module that is used by JSON.
|
828
|
+
#
|
829
|
+
def self.generator: () -> generator
|
830
|
+
|
831
|
+
def self.generator=: (generator generator) -> void
|
832
|
+
|
833
|
+
# <!--
|
834
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
835
|
+
# - iconv(to, from, string)
|
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
|
843
|
+
# - JSON.load(source, proc = nil, options = {}) -> object
|
844
|
+
# -->
|
845
|
+
# Returns the Ruby objects created by parsing the given `source`.
|
846
|
+
#
|
847
|
+
# BEWARE: This method is meant to serialise data from trusted user input, like
|
848
|
+
# from your own database server or clients under your control, it could be
|
849
|
+
# dangerous to allow untrusted users to pass JSON sources into it. If you must
|
850
|
+
# use it, use JSON.unsafe_load instead to make it clear.
|
851
|
+
#
|
852
|
+
# Since JSON version 2.8.0, `load` emits a deprecation warning when a non native
|
853
|
+
# type is deserialized, without `create_additions` being explicitly enabled, and
|
854
|
+
# in JSON version 3.0, `load` will have `create_additions` disabled by default.
|
855
|
+
#
|
856
|
+
# * Argument `source` must be, or be convertible to, a String:
|
857
|
+
# * If `source` responds to instance method `to_str`, `source.to_str`
|
858
|
+
# becomes the source.
|
859
|
+
# * If `source` responds to instance method `to_io`, `source.to_io.read`
|
860
|
+
# becomes the source.
|
861
|
+
# * If `source` responds to instance method `read`, `source.read` becomes
|
862
|
+
# the source.
|
863
|
+
# * If both of the following are true, source becomes the String `'null'`:
|
864
|
+
# * Option `allow_blank` specifies a truthy value.
|
865
|
+
# * The source, as defined above, is `nil` or the empty String `''`.
|
866
|
+
# * Otherwise, `source` remains the source.
|
867
|
+
# * Argument `proc`, if given, must be a Proc that accepts one argument. It
|
868
|
+
# will be called recursively with each result (depth-first order). See
|
869
|
+
# details below.
|
870
|
+
# * Argument `opts`, if given, contains a Hash of options for the parsing. See
|
871
|
+
# [Parsing Options](#module-JSON-label-Parsing+Options). The default options
|
872
|
+
# can be changed via method JSON.load_default_options=.
|
873
|
+
#
|
874
|
+
# ---
|
875
|
+
#
|
876
|
+
# When no `proc` is given, modifies `source` as above and returns the result of
|
877
|
+
# `parse(source, opts)`; see #parse.
|
878
|
+
#
|
879
|
+
# Source for following examples:
|
880
|
+
# source = <<~JSON
|
881
|
+
# {
|
882
|
+
# "name": "Dave",
|
883
|
+
# "age" :40,
|
884
|
+
# "hats": [
|
885
|
+
# "Cattleman's",
|
886
|
+
# "Panama",
|
887
|
+
# "Tophat"
|
888
|
+
# ]
|
889
|
+
# }
|
890
|
+
# JSON
|
891
|
+
#
|
892
|
+
# Load a String:
|
893
|
+
# ruby = JSON.load(source)
|
894
|
+
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
895
|
+
#
|
896
|
+
# Load an IO object:
|
897
|
+
# require 'stringio'
|
898
|
+
# object = JSON.load(StringIO.new(source))
|
899
|
+
# object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
900
|
+
#
|
901
|
+
# Load a File object:
|
902
|
+
# path = 't.json'
|
903
|
+
# File.write(path, source)
|
904
|
+
# File.open(path) do |file|
|
905
|
+
# JSON.load(file)
|
906
|
+
# end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
907
|
+
#
|
908
|
+
# ---
|
909
|
+
#
|
910
|
+
# When `proc` is given:
|
911
|
+
# * Modifies `source` as above.
|
912
|
+
# * Gets the `result` from calling `parse(source, opts)`.
|
913
|
+
# * Recursively calls `proc(result)`.
|
914
|
+
# * Returns the final result.
|
915
|
+
#
|
916
|
+
# Example:
|
917
|
+
# require 'json'
|
918
|
+
#
|
919
|
+
# # Some classes for the example.
|
920
|
+
# class Base
|
921
|
+
# def initialize(attributes)
|
922
|
+
# @attributes = attributes
|
923
|
+
# end
|
924
|
+
# end
|
925
|
+
# class User < Base; end
|
926
|
+
# class Account < Base; end
|
927
|
+
# class Admin < Base; end
|
928
|
+
# # The JSON source.
|
929
|
+
# json = <<-EOF
|
930
|
+
# {
|
931
|
+
# "users": [
|
932
|
+
# {"type": "User", "username": "jane", "email": "jane@example.com"},
|
933
|
+
# {"type": "User", "username": "john", "email": "john@example.com"}
|
934
|
+
# ],
|
935
|
+
# "accounts": [
|
936
|
+
# {"account": {"type": "Account", "paid": true, "account_id": "1234"}},
|
937
|
+
# {"account": {"type": "Account", "paid": false, "account_id": "1235"}}
|
938
|
+
# ],
|
939
|
+
# "admins": {"type": "Admin", "password": "0wn3d"}
|
940
|
+
# }
|
941
|
+
# EOF
|
942
|
+
# # Deserializer method.
|
943
|
+
# def deserialize_obj(obj, safe_types = %w(User Account Admin))
|
944
|
+
# type = obj.is_a?(Hash) && obj["type"]
|
945
|
+
# safe_types.include?(type) ? Object.const_get(type).new(obj) : obj
|
946
|
+
# end
|
947
|
+
# # Call to JSON.load
|
948
|
+
# ruby = JSON.load(json, proc {|obj|
|
949
|
+
# case obj
|
950
|
+
# when Hash
|
951
|
+
# obj.each {|k, v| obj[k] = deserialize_obj v }
|
952
|
+
# when Array
|
953
|
+
# obj.map! {|v| deserialize_obj v }
|
954
|
+
# end
|
955
|
+
# })
|
956
|
+
# pp ruby
|
957
|
+
#
|
958
|
+
# Output:
|
959
|
+
# {"users"=>
|
960
|
+
# [#<User:0x00000000064c4c98
|
961
|
+
# @attributes=
|
962
|
+
# {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>,
|
963
|
+
# #<User:0x00000000064c4bd0
|
964
|
+
# @attributes=
|
965
|
+
# {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>],
|
966
|
+
# "accounts"=>
|
967
|
+
# [{"account"=>
|
968
|
+
# #<Account:0x00000000064c4928
|
969
|
+
# @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>},
|
970
|
+
# {"account"=>
|
971
|
+
# #<Account:0x00000000064c4680
|
972
|
+
# @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}],
|
973
|
+
# "admins"=>
|
974
|
+
# #<Admin:0x00000000064c41f8
|
975
|
+
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
|
976
|
+
#
|
977
|
+
def self?.load: (string | _ReadableIO | _Read source, ?Proc proc, ?options options) -> untyped
|
978
|
+
|
979
|
+
# <!--
|
980
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
981
|
+
# - JSON.load_file(path, opts={}) -> object
|
982
|
+
# -->
|
983
|
+
# Calls:
|
984
|
+
# parse(File.read(path), opts)
|
985
|
+
#
|
986
|
+
# See method #parse.
|
987
|
+
#
|
988
|
+
def self?.load_file: (string path, ?options opts) -> untyped
|
989
|
+
|
990
|
+
# <!--
|
991
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
992
|
+
# - JSON.load_file!(path, opts = {})
|
993
|
+
# -->
|
994
|
+
# Calls:
|
995
|
+
# JSON.parse!(File.read(path, opts))
|
996
|
+
#
|
997
|
+
# See method #parse!
|
998
|
+
#
|
999
|
+
def self?.load_file!: (string path, ?options opts) -> untyped
|
1000
|
+
|
1001
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
1002
|
+
# Sets or returns default options for the JSON.load method. Initially:
|
1003
|
+
# opts = JSON.load_default_options
|
1004
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
1005
|
+
#
|
1006
|
+
def self.load_default_options: () -> options
|
1007
|
+
|
1008
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
1009
|
+
# Sets or returns default options for the JSON.load method. Initially:
|
1010
|
+
# opts = JSON.load_default_options
|
1011
|
+
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
|
1012
|
+
#
|
1013
|
+
def self.load_default_options=: (options) -> options
|
1014
|
+
|
1015
|
+
# <!--
|
1016
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
1017
|
+
# - JSON.parse(source, opts) -> object
|
1018
|
+
# -->
|
1019
|
+
# Returns the Ruby objects created by parsing the given `source`.
|
1020
|
+
#
|
1021
|
+
# Argument `source` contains the String to be parsed.
|
1022
|
+
#
|
1023
|
+
# Argument `opts`, if given, contains a Hash of options for the parsing. See
|
1024
|
+
# [Parsing Options](#module-JSON-label-Parsing+Options).
|
1025
|
+
#
|
1026
|
+
# ---
|
1027
|
+
#
|
1028
|
+
# When `source` is a JSON array, returns a Ruby Array:
|
1029
|
+
# source = '["foo", 1.0, true, false, null]'
|
1030
|
+
# ruby = JSON.parse(source)
|
1031
|
+
# ruby # => ["foo", 1.0, true, false, nil]
|
1032
|
+
# ruby.class # => Array
|
1033
|
+
#
|
1034
|
+
# When `source` is a JSON object, returns a Ruby Hash:
|
1035
|
+
# source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
|
1036
|
+
# ruby = JSON.parse(source)
|
1037
|
+
# ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
|
1038
|
+
# ruby.class # => Hash
|
1039
|
+
#
|
1040
|
+
# For examples of parsing for all JSON data types, see [Parsing
|
1041
|
+
# \JSON](#module-JSON-label-Parsing+JSON).
|
1042
|
+
#
|
1043
|
+
# Parses nested JSON objects:
|
1044
|
+
# source = <<~JSON
|
1045
|
+
# {
|
1046
|
+
# "name": "Dave",
|
1047
|
+
# "age" :40,
|
1048
|
+
# "hats": [
|
1049
|
+
# "Cattleman's",
|
1050
|
+
# "Panama",
|
1051
|
+
# "Tophat"
|
1052
|
+
# ]
|
1053
|
+
# }
|
1054
|
+
# JSON
|
1055
|
+
# ruby = JSON.parse(source)
|
1056
|
+
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
|
1057
|
+
#
|
1058
|
+
# ---
|
1059
|
+
#
|
1060
|
+
# Raises an exception if `source` is not valid JSON:
|
1061
|
+
# # Raises JSON::ParserError (783: unexpected token at ''):
|
1062
|
+
# JSON.parse('')
|
1063
|
+
#
|
1064
|
+
def self?.parse: (string source, ?options opts) -> untyped
|
1065
|
+
|
1066
|
+
# <!--
|
1067
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
1068
|
+
# - JSON.parse!(source, opts) -> object
|
1069
|
+
# -->
|
1070
|
+
# Calls
|
1071
|
+
# parse(source, opts)
|
1072
|
+
#
|
1073
|
+
# with `source` and possibly modified `opts`.
|
1074
|
+
#
|
1075
|
+
# Differences from JSON.parse:
|
1076
|
+
# * Option `max_nesting`, if not provided, defaults to `false`, which disables
|
1077
|
+
# checking for nesting depth.
|
1078
|
+
# * Option `allow_nan`, if not provided, defaults to `true`.
|
1079
|
+
#
|
1080
|
+
def self?.parse!: (string source, ?options opts) -> untyped
|
1081
|
+
|
1082
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
1083
|
+
# Returns the JSON parser class that is used by JSON.
|
1084
|
+
#
|
1085
|
+
def self.parser: () -> parser
|
1086
|
+
|
1087
|
+
def self.parser=: (parser parser) -> void
|
1088
|
+
|
1089
|
+
# <!--
|
1090
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
1091
|
+
# - JSON.pretty_generate(obj, opts = nil) -> new_string
|
1092
|
+
# -->
|
1093
|
+
# Arguments `obj` and `opts` here are the same as arguments `obj` and `opts` in
|
1094
|
+
# JSON.generate.
|
1095
|
+
#
|
1096
|
+
# Default options are:
|
1097
|
+
# {
|
1098
|
+
# indent: ' ', # Two spaces
|
1099
|
+
# space: ' ', # One space
|
1100
|
+
# array_nl: "\n", # Newline
|
1101
|
+
# object_nl: "\n" # Newline
|
1102
|
+
# }
|
1103
|
+
#
|
1104
|
+
# Example:
|
1105
|
+
# obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
|
1106
|
+
# json = JSON.pretty_generate(obj)
|
1107
|
+
# puts json
|
1108
|
+
#
|
1109
|
+
# Output:
|
1110
|
+
# {
|
1111
|
+
# "foo": [
|
1112
|
+
# "bar",
|
1113
|
+
# "baz"
|
1114
|
+
# ],
|
1115
|
+
# "bat": {
|
1116
|
+
# "bam": 0,
|
1117
|
+
# "bad": 1
|
1118
|
+
# }
|
1119
|
+
# }
|
1120
|
+
#
|
1121
|
+
def self?.pretty_generate: (_ToJson obj, ?options opts) -> untyped
|
1122
|
+
|
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
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
1147
|
+
# Sets or Returns the JSON generator state class that is used by JSON.
|
1148
|
+
#
|
1149
|
+
def self.state: () -> state
|
1150
|
+
|
1151
|
+
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
|
1152
|
+
# Sets or Returns the JSON generator state class that is used by JSON.
|
1153
|
+
#
|
1154
|
+
def self.state=: (state) -> state
|
1155
|
+
|
1156
|
+
alias self.unparse self.generate
|
1157
|
+
|
1158
|
+
alias unparse generate
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
JSON::FAST_STATE_PROTOTYPE: JSON::state
|
1162
|
+
|
1163
|
+
JSON::Infinity: Float
|
1164
|
+
|
1165
|
+
JSON::JSON_LOADED: bool
|
1166
|
+
|
1167
|
+
JSON::MinusInfinity: Float
|
1168
|
+
|
1169
|
+
JSON::NaN: Float
|
1170
|
+
|
1171
|
+
JSON::PRETTY_STATE_PROTOTYPE: JSON::state
|
1172
|
+
|
1173
|
+
JSON::SAFE_STATE_PROTOTYPE: JSON::state
|
1174
|
+
|
1175
|
+
JSON::VERSION: String
|
1176
|
+
|
1177
|
+
JSON::VERSION_ARRAY: Array[Integer]
|
1178
|
+
|
1179
|
+
JSON::VERSION_BUILD: Integer
|
1180
|
+
|
1181
|
+
JSON::VERSION_MAJOR: Integer
|
1182
|
+
|
1183
|
+
JSON::VERSION_MINOR: Integer
|
1184
|
+
|
1185
|
+
%a{annotate:rdoc:skip}
|
1186
|
+
module Kernel
|
1187
|
+
private
|
1188
|
+
|
1189
|
+
# <!--
|
1190
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
1191
|
+
# - j(*objs)
|
1192
|
+
# -->
|
1193
|
+
# Outputs *objs* to STDOUT as JSON strings in the shortest form, that is in one
|
1194
|
+
# line.
|
1195
|
+
#
|
1196
|
+
def j: (*_ToJson) -> nil
|
1197
|
+
|
1198
|
+
# <!--
|
1199
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
1200
|
+
# - jj(*objs)
|
1201
|
+
# -->
|
1202
|
+
# Outputs *objs* to STDOUT as JSON strings in a pretty format, with indentation
|
1203
|
+
# and over many lines.
|
1204
|
+
#
|
1205
|
+
def jj: (*_ToJson) -> nil
|
1206
|
+
|
1207
|
+
# <!--
|
1208
|
+
# rdoc-file=ext/json/lib/json/common.rb
|
1209
|
+
# - JSON(object, *args)
|
1210
|
+
# -->
|
1211
|
+
# If *object* is string-like, parse the string and return the parsed result as a
|
1212
|
+
# Ruby data structure. Otherwise, generate a JSON text from the Ruby data
|
1213
|
+
# structure object and return it.
|
1214
|
+
#
|
1215
|
+
# The *opts* argument is passed through to generate/parse respectively. See
|
1216
|
+
# generate and parse for their documentation.
|
1217
|
+
#
|
1218
|
+
def JSON: (string source, ?JSON::options opts) -> untyped
|
1219
|
+
| (_ToJson obj, ?JSON::options opts) -> String
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
%a{annotate:rdoc:skip}
|
1223
|
+
class Object
|
1224
|
+
# Converts this object to a string (calling #to_s), converts
|
1225
|
+
# it to a JSON string, and returns the result. This is a fallback, if no
|
1226
|
+
# special method #to_json was defined for some object.
|
1227
|
+
#
|
1228
|
+
def to_json: (?JSON::State state) -> String
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
%a{annotate:rdoc:skip}
|
1232
|
+
class NilClass
|
1233
|
+
# Returns a JSON string for nil: 'null'.
|
1234
|
+
#
|
1235
|
+
def to_json: (?JSON::State state) -> String
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
%a{annotate:rdoc:skip}
|
1239
|
+
class TrueClass
|
1240
|
+
# Returns a JSON string for true: 'true'.
|
1241
|
+
#
|
1242
|
+
def to_json: (?JSON::State state) -> String
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
%a{annotate:rdoc:skip}
|
1246
|
+
class FalseClass
|
1247
|
+
# Returns a JSON string for false: 'false'.
|
1248
|
+
#
|
1249
|
+
def to_json: (?JSON::State state) -> String
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
%a{annotate:rdoc:skip}
|
1253
|
+
class String
|
1254
|
+
# This string should be encoded with UTF-8 A call to this method
|
1255
|
+
# returns a JSON string encoded with UTF16 big endian characters as
|
1256
|
+
# \u????.
|
1257
|
+
#
|
1258
|
+
def to_json: (?JSON::State state) -> String
|
1259
|
+
end
|
1260
|
+
|
1261
|
+
%a{annotate:rdoc:skip}
|
1262
|
+
class Integer
|
1263
|
+
# Returns a JSON string representation for this Integer number.
|
1264
|
+
#
|
1265
|
+
def to_json: (?JSON::State state) -> String
|
1266
|
+
end
|
1267
|
+
|
1268
|
+
%a{annotate:rdoc:skip}
|
1269
|
+
class Float
|
1270
|
+
# Returns a JSON string representation for this Float number.
|
1271
|
+
#
|
1272
|
+
def to_json: (?JSON::State state) -> String
|
1273
|
+
end
|
1274
|
+
|
1275
|
+
%a{annotate:rdoc:skip}
|
1276
|
+
class Hash[unchecked out K, unchecked out V]
|
1277
|
+
# Returns a JSON string containing a JSON object, that is generated from
|
1278
|
+
# this Hash instance.
|
1279
|
+
# _state_ is a JSON::State object, that can also be used to configure the
|
1280
|
+
# produced JSON string output further.
|
1281
|
+
#
|
1282
|
+
def to_json: (?JSON::State state) -> String
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
%a{annotate:rdoc:skip}
|
1286
|
+
class Array[unchecked out Elem]
|
1287
|
+
# Returns a JSON string containing a JSON array, that is generated from
|
1288
|
+
# this Array instance.
|
1289
|
+
# _state_ is a JSON::State object, that can also be used to configure the
|
1290
|
+
# produced JSON string output further.
|
1291
|
+
#
|
1292
|
+
def to_json: (?JSON::State state) -> String
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
%a{annotate:rdoc:skip}
|
1296
|
+
class BigDecimal
|
1297
|
+
# <!--
|
1298
|
+
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
1299
|
+
# - json_create(object)
|
1300
|
+
# -->
|
1301
|
+
# See #as_json.
|
1302
|
+
#
|
1303
|
+
def self.json_create: (Hash[String, String] object) -> instance
|
1304
|
+
|
1305
|
+
# <!--
|
1306
|
+
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
1307
|
+
# - as_json(*)
|
1308
|
+
# -->
|
1309
|
+
# Methods `BigDecimal#as_json` and `BigDecimal.json_create` may be used to
|
1310
|
+
# serialize and deserialize a BigDecimal object; see
|
1311
|
+
# [Marshal](rdoc-ref:Marshal).
|
1312
|
+
#
|
1313
|
+
# Method `BigDecimal#as_json` serializes `self`, returning a 2-element hash
|
1314
|
+
# representing `self`:
|
1315
|
+
#
|
1316
|
+
# require 'json/add/bigdecimal'
|
1317
|
+
# x = BigDecimal(2).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
1318
|
+
# y = BigDecimal(2.0, 4).as_json # => {"json_class"=>"BigDecimal", "b"=>"36:0.2e1"}
|
1319
|
+
# z = BigDecimal(Complex(2, 0)).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
1320
|
+
#
|
1321
|
+
# Method `JSON.create` deserializes such a hash, returning a BigDecimal object:
|
1322
|
+
#
|
1323
|
+
# BigDecimal.json_create(x) # => 0.2e1
|
1324
|
+
# BigDecimal.json_create(y) # => 0.2e1
|
1325
|
+
# BigDecimal.json_create(z) # => 0.2e1
|
1326
|
+
#
|
1327
|
+
def as_json: (*untyped) -> Hash[String, String]
|
1328
|
+
|
1329
|
+
# <!--
|
1330
|
+
# rdoc-file=ext/json/lib/json/add/bigdecimal.rb
|
1331
|
+
# - to_json(*args)
|
1332
|
+
# -->
|
1333
|
+
# Returns a JSON string representing `self`:
|
1334
|
+
#
|
1335
|
+
# require 'json/add/bigdecimal'
|
1336
|
+
# puts BigDecimal(2).to_json
|
1337
|
+
# puts BigDecimal(2.0, 4).to_json
|
1338
|
+
# puts BigDecimal(Complex(2, 0)).to_json
|
1339
|
+
#
|
1340
|
+
# Output:
|
1341
|
+
#
|
1342
|
+
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
1343
|
+
# {"json_class":"BigDecimal","b":"36:0.2e1"}
|
1344
|
+
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
1345
|
+
#
|
1346
|
+
def to_json: (?JSON::State state) -> String
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
%a{annotate:rdoc:skip}
|
1350
|
+
class Complex
|
1351
|
+
# <!--
|
1352
|
+
# rdoc-file=ext/json/lib/json/add/complex.rb
|
1353
|
+
# - json_create(object)
|
1354
|
+
# -->
|
1355
|
+
# See #as_json.
|
1356
|
+
#
|
1357
|
+
def self.json_create: (Hash[String, String | Numeric] object) -> instance
|
1358
|
+
|
1359
|
+
# <!--
|
1360
|
+
# rdoc-file=ext/json/lib/json/add/complex.rb
|
1361
|
+
# - as_json(*)
|
1362
|
+
# -->
|
1363
|
+
# Methods `Complex#as_json` and `Complex.json_create` may be used to serialize
|
1364
|
+
# and deserialize a Complex object; see [Marshal](rdoc-ref:Marshal).
|
1365
|
+
#
|
1366
|
+
# Method `Complex#as_json` serializes `self`, returning a 2-element hash
|
1367
|
+
# representing `self`:
|
1368
|
+
#
|
1369
|
+
# require 'json/add/complex'
|
1370
|
+
# x = Complex(2).as_json # => {"json_class"=>"Complex", "r"=>2, "i"=>0}
|
1371
|
+
# y = Complex(2.0, 4).as_json # => {"json_class"=>"Complex", "r"=>2.0, "i"=>4}
|
1372
|
+
#
|
1373
|
+
# Method `JSON.create` deserializes such a hash, returning a Complex object:
|
1374
|
+
#
|
1375
|
+
# Complex.json_create(x) # => (2+0i)
|
1376
|
+
# Complex.json_create(y) # => (2.0+4i)
|
1377
|
+
#
|
1378
|
+
def as_json: (*untyped) -> Hash[String, String | Numeric]
|
1379
|
+
|
1380
|
+
# <!--
|
1381
|
+
# rdoc-file=ext/json/lib/json/add/complex.rb
|
1382
|
+
# - to_json(*args)
|
1383
|
+
# -->
|
1384
|
+
# Returns a JSON string representing `self`:
|
1385
|
+
#
|
1386
|
+
# require 'json/add/complex'
|
1387
|
+
# puts Complex(2).to_json
|
1388
|
+
# puts Complex(2.0, 4).to_json
|
1389
|
+
#
|
1390
|
+
# Output:
|
1391
|
+
#
|
1392
|
+
# {"json_class":"Complex","r":2,"i":0}
|
1393
|
+
# {"json_class":"Complex","r":2.0,"i":4}
|
1394
|
+
#
|
1395
|
+
def to_json: (?JSON::State state) -> String
|
1396
|
+
end
|
1397
|
+
|
1398
|
+
%a{annotate:rdoc:skip}
|
1399
|
+
class Date
|
1400
|
+
# <!--
|
1401
|
+
# rdoc-file=ext/json/lib/json/add/date.rb
|
1402
|
+
# - json_create(object)
|
1403
|
+
# -->
|
1404
|
+
# See #as_json.
|
1405
|
+
#
|
1406
|
+
def self.json_create: (Hash[String, String | Integer | Float] object) -> instance
|
1407
|
+
|
1408
|
+
# <!--
|
1409
|
+
# rdoc-file=ext/json/lib/json/add/date.rb
|
1410
|
+
# - as_json(*)
|
1411
|
+
# -->
|
1412
|
+
# Methods `Date#as_json` and `Date.json_create` may be used to serialize and
|
1413
|
+
# deserialize a Date object; see [Marshal](rdoc-ref:Marshal).
|
1414
|
+
#
|
1415
|
+
# Method `Date#as_json` serializes `self`, returning a 2-element hash
|
1416
|
+
# representing `self`:
|
1417
|
+
#
|
1418
|
+
# require 'json/add/date'
|
1419
|
+
# x = Date.today.as_json
|
1420
|
+
# # => {"json_class"=>"Date", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
1421
|
+
#
|
1422
|
+
# Method `JSON.create` deserializes such a hash, returning a Date object:
|
1423
|
+
#
|
1424
|
+
# Date.json_create(x)
|
1425
|
+
# # => #<Date: 2023-11-21 ((2460270j,0s,0n),+0s,2299161j)>
|
1426
|
+
#
|
1427
|
+
def as_json: (*untyped) -> Hash[String, String | Integer | Float]
|
1428
|
+
|
1429
|
+
# <!--
|
1430
|
+
# rdoc-file=ext/json/lib/json/add/date.rb
|
1431
|
+
# - to_json(*args)
|
1432
|
+
# -->
|
1433
|
+
# Returns a JSON string representing `self`:
|
1434
|
+
#
|
1435
|
+
# require 'json/add/date'
|
1436
|
+
# puts Date.today.to_json
|
1437
|
+
#
|
1438
|
+
# Output:
|
1439
|
+
#
|
1440
|
+
# {"json_class":"Date","y":2023,"m":11,"d":21,"sg":2299161.0}
|
1441
|
+
#
|
1442
|
+
def to_json: (?JSON::State state) -> String
|
1443
|
+
end
|
1444
|
+
|
1445
|
+
%a{annotate:rdoc:skip}
|
1446
|
+
class DateTime
|
1447
|
+
# <!--
|
1448
|
+
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
1449
|
+
# - json_create(object)
|
1450
|
+
# -->
|
1451
|
+
# See #as_json.
|
1452
|
+
#
|
1453
|
+
def self.json_create: (Hash[String, String | Integer | Float] object) -> instance
|
1454
|
+
|
1455
|
+
# <!--
|
1456
|
+
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
1457
|
+
# - as_json(*)
|
1458
|
+
# -->
|
1459
|
+
# Methods `DateTime#as_json` and `DateTime.json_create` may be used to serialize
|
1460
|
+
# and deserialize a DateTime object; see [Marshal](rdoc-ref:Marshal).
|
1461
|
+
#
|
1462
|
+
# Method `DateTime#as_json` serializes `self`, returning a 2-element hash
|
1463
|
+
# representing `self`:
|
1464
|
+
#
|
1465
|
+
# require 'json/add/datetime'
|
1466
|
+
# x = DateTime.now.as_json
|
1467
|
+
# # => {"json_class"=>"DateTime", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
1468
|
+
#
|
1469
|
+
# Method `JSON.create` deserializes such a hash, returning a DateTime object:
|
1470
|
+
#
|
1471
|
+
# DateTime.json_create(x) # BUG? Raises Date::Error "invalid date"
|
1472
|
+
#
|
1473
|
+
def as_json: (*untyped) -> Hash[String, String | Integer | Float]
|
1474
|
+
|
1475
|
+
# <!--
|
1476
|
+
# rdoc-file=ext/json/lib/json/add/date_time.rb
|
1477
|
+
# - to_json(*args)
|
1478
|
+
# -->
|
1479
|
+
# Returns a JSON string representing `self`:
|
1480
|
+
#
|
1481
|
+
# require 'json/add/datetime'
|
1482
|
+
# puts DateTime.now.to_json
|
1483
|
+
#
|
1484
|
+
# Output:
|
1485
|
+
#
|
1486
|
+
# {"json_class":"DateTime","y":2023,"m":11,"d":21,"sg":2299161.0}
|
1487
|
+
#
|
1488
|
+
def to_json: (?JSON::State state) -> String
|
1489
|
+
end
|
1490
|
+
|
1491
|
+
%a{annotate:rdoc:skip}
|
1492
|
+
class Exception
|
1493
|
+
# <!--
|
1494
|
+
# rdoc-file=ext/json/lib/json/add/exception.rb
|
1495
|
+
# - json_create(object)
|
1496
|
+
# -->
|
1497
|
+
# See #as_json.
|
1498
|
+
#
|
1499
|
+
def self.json_create: (Hash[String, String | Array[String] | nil] object) -> instance
|
1500
|
+
|
1501
|
+
# <!--
|
1502
|
+
# rdoc-file=ext/json/lib/json/add/exception.rb
|
1503
|
+
# - as_json(*)
|
1504
|
+
# -->
|
1505
|
+
# Methods `Exception#as_json` and `Exception.json_create` may be used to
|
1506
|
+
# serialize and deserialize a Exception object; see [Marshal](rdoc-ref:Marshal).
|
1507
|
+
#
|
1508
|
+
# Method `Exception#as_json` serializes `self`, returning a 2-element hash
|
1509
|
+
# representing `self`:
|
1510
|
+
#
|
1511
|
+
# require 'json/add/exception'
|
1512
|
+
# x = Exception.new('Foo').as_json # => {"json_class"=>"Exception", "m"=>"Foo", "b"=>nil}
|
1513
|
+
#
|
1514
|
+
# Method `JSON.create` deserializes such a hash, returning a Exception object:
|
1515
|
+
#
|
1516
|
+
# Exception.json_create(x) # => #<Exception: Foo>
|
1517
|
+
#
|
1518
|
+
def as_json: (*untyped) -> Hash[String, String | Array[String] | nil]
|
1519
|
+
|
1520
|
+
# <!--
|
1521
|
+
# rdoc-file=ext/json/lib/json/add/exception.rb
|
1522
|
+
# - to_json(*args)
|
1523
|
+
# -->
|
1524
|
+
# Returns a JSON string representing `self`:
|
1525
|
+
#
|
1526
|
+
# require 'json/add/exception'
|
1527
|
+
# puts Exception.new('Foo').to_json
|
1528
|
+
#
|
1529
|
+
# Output:
|
1530
|
+
#
|
1531
|
+
# {"json_class":"Exception","m":"Foo","b":null}
|
1532
|
+
#
|
1533
|
+
def to_json: (?JSON::State state) -> String
|
1534
|
+
end
|
1535
|
+
|
1536
|
+
%a{annotate:rdoc:skip}
|
1537
|
+
class OpenStruct
|
1538
|
+
# <!--
|
1539
|
+
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
1540
|
+
# - json_create(object)
|
1541
|
+
# -->
|
1542
|
+
# See #as_json.
|
1543
|
+
#
|
1544
|
+
def self.json_create: (Hash[String, String | Hash[Symbol, untyped]] object) -> instance
|
1545
|
+
|
1546
|
+
# <!--
|
1547
|
+
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
1548
|
+
# - as_json(*)
|
1549
|
+
# -->
|
1550
|
+
# Methods `OpenStruct#as_json` and `OpenStruct.json_create` may be used to
|
1551
|
+
# serialize and deserialize a OpenStruct object; see
|
1552
|
+
# [Marshal](rdoc-ref:Marshal).
|
1553
|
+
#
|
1554
|
+
# Method `OpenStruct#as_json` serializes `self`, returning a 2-element hash
|
1555
|
+
# representing `self`:
|
1556
|
+
#
|
1557
|
+
# require 'json/add/ostruct'
|
1558
|
+
# x = OpenStruct.new('name' => 'Rowdy', :age => nil).as_json
|
1559
|
+
# # => {"json_class"=>"OpenStruct", "t"=>{:name=>'Rowdy', :age=>nil}}
|
1560
|
+
#
|
1561
|
+
# Method `JSON.create` deserializes such a hash, returning a OpenStruct object:
|
1562
|
+
#
|
1563
|
+
# OpenStruct.json_create(x)
|
1564
|
+
# # => #<OpenStruct name='Rowdy', age=nil>
|
1565
|
+
#
|
1566
|
+
def as_json: (*untyped) -> Hash[String, String | Hash[Symbol, untyped]]
|
1567
|
+
|
1568
|
+
# <!--
|
1569
|
+
# rdoc-file=ext/json/lib/json/add/ostruct.rb
|
1570
|
+
# - to_json(*args)
|
1571
|
+
# -->
|
1572
|
+
# Returns a JSON string representing `self`:
|
1573
|
+
#
|
1574
|
+
# require 'json/add/ostruct'
|
1575
|
+
# puts OpenStruct.new('name' => 'Rowdy', :age => nil).to_json
|
1576
|
+
#
|
1577
|
+
# Output:
|
1578
|
+
#
|
1579
|
+
# {"json_class":"OpenStruct","t":{'name':'Rowdy',"age":null}}
|
1580
|
+
#
|
1581
|
+
def to_json: (?JSON::State state) -> String
|
1582
|
+
end
|
1583
|
+
|
1584
|
+
%a{annotate:rdoc:skip}
|
1585
|
+
class Range[out Elem]
|
1586
|
+
# <!--
|
1587
|
+
# rdoc-file=ext/json/lib/json/add/range.rb
|
1588
|
+
# - json_create(object)
|
1589
|
+
# -->
|
1590
|
+
# See #as_json.
|
1591
|
+
#
|
1592
|
+
def self.json_create: [A] (Hash[String, String | [ A, A, bool ]] object) -> Range[A]
|
1593
|
+
|
1594
|
+
# <!--
|
1595
|
+
# rdoc-file=ext/json/lib/json/add/range.rb
|
1596
|
+
# - as_json(*)
|
1597
|
+
# -->
|
1598
|
+
# Methods `Range#as_json` and `Range.json_create` may be used to serialize and
|
1599
|
+
# deserialize a Range object; see [Marshal](rdoc-ref:Marshal).
|
1600
|
+
#
|
1601
|
+
# Method `Range#as_json` serializes `self`, returning a 2-element hash
|
1602
|
+
# representing `self`:
|
1603
|
+
#
|
1604
|
+
# require 'json/add/range'
|
1605
|
+
# x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
1606
|
+
# y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
1607
|
+
# z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
1608
|
+
#
|
1609
|
+
# Method `JSON.create` deserializes such a hash, returning a Range object:
|
1610
|
+
#
|
1611
|
+
# Range.json_create(x) # => 1..4
|
1612
|
+
# Range.json_create(y) # => 1...4
|
1613
|
+
# Range.json_create(z) # => "a".."d"
|
1614
|
+
#
|
1615
|
+
def as_json: (*untyped) -> Hash[String, String | [ Elem, Elem, bool ]]
|
1616
|
+
|
1617
|
+
# <!--
|
1618
|
+
# rdoc-file=ext/json/lib/json/add/range.rb
|
1619
|
+
# - to_json(*args)
|
1620
|
+
# -->
|
1621
|
+
# Returns a JSON string representing `self`:
|
1622
|
+
#
|
1623
|
+
# require 'json/add/range'
|
1624
|
+
# puts (1..4).to_json
|
1625
|
+
# puts (1...4).to_json
|
1626
|
+
# puts ('a'..'d').to_json
|
1627
|
+
#
|
1628
|
+
# Output:
|
1629
|
+
#
|
1630
|
+
# {"json_class":"Range","a":[1,4,false]}
|
1631
|
+
# {"json_class":"Range","a":[1,4,true]}
|
1632
|
+
# {"json_class":"Range","a":["a","d",false]}
|
1633
|
+
#
|
1634
|
+
def to_json: (?JSON::State state) -> String
|
1635
|
+
end
|
1636
|
+
|
1637
|
+
%a{annotate:rdoc:skip}
|
1638
|
+
class Rational
|
1639
|
+
# <!--
|
1640
|
+
# rdoc-file=ext/json/lib/json/add/rational.rb
|
1641
|
+
# - json_create(object)
|
1642
|
+
# -->
|
1643
|
+
# See #as_json.
|
1644
|
+
#
|
1645
|
+
def self.json_create: (Hash[String, String | Integer] object) -> instance
|
1646
|
+
|
1647
|
+
# <!--
|
1648
|
+
# rdoc-file=ext/json/lib/json/add/rational.rb
|
1649
|
+
# - as_json(*)
|
1650
|
+
# -->
|
1651
|
+
# Methods `Rational#as_json` and `Rational.json_create` may be used to serialize
|
1652
|
+
# and deserialize a Rational object; see [Marshal](rdoc-ref:Marshal).
|
1653
|
+
#
|
1654
|
+
# Method `Rational#as_json` serializes `self`, returning a 2-element hash
|
1655
|
+
# representing `self`:
|
1656
|
+
#
|
1657
|
+
# require 'json/add/rational'
|
1658
|
+
# x = Rational(2, 3).as_json
|
1659
|
+
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
1660
|
+
#
|
1661
|
+
# Method `JSON.create` deserializes such a hash, returning a Rational object:
|
1662
|
+
#
|
1663
|
+
# Rational.json_create(x)
|
1664
|
+
# # => (2/3)
|
1665
|
+
#
|
1666
|
+
def as_json: (*untyped) -> Hash[String, String | Integer]
|
1667
|
+
|
1668
|
+
# <!--
|
1669
|
+
# rdoc-file=ext/json/lib/json/add/rational.rb
|
1670
|
+
# - to_json(*args)
|
1671
|
+
# -->
|
1672
|
+
# Returns a JSON string representing `self`:
|
1673
|
+
#
|
1674
|
+
# require 'json/add/rational'
|
1675
|
+
# puts Rational(2, 3).to_json
|
1676
|
+
#
|
1677
|
+
# Output:
|
1678
|
+
#
|
1679
|
+
# {"json_class":"Rational","n":2,"d":3}
|
1680
|
+
#
|
1681
|
+
def to_json: (?JSON::State state) -> String
|
1682
|
+
end
|
1683
|
+
|
1684
|
+
%a{annotate:rdoc:skip}
|
1685
|
+
class Regexp
|
1686
|
+
# <!--
|
1687
|
+
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
1688
|
+
# - json_create(object)
|
1689
|
+
# -->
|
1690
|
+
# See #as_json.
|
1691
|
+
#
|
1692
|
+
def self.json_create: (Hash[String, String | Integer] object) -> instance
|
1693
|
+
|
1694
|
+
# <!--
|
1695
|
+
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
1696
|
+
# - as_json(*)
|
1697
|
+
# -->
|
1698
|
+
# Methods `Regexp#as_json` and `Regexp.json_create` may be used to serialize and
|
1699
|
+
# deserialize a Regexp object; see [Marshal](rdoc-ref:Marshal).
|
1700
|
+
#
|
1701
|
+
# Method `Regexp#as_json` serializes `self`, returning a 2-element hash
|
1702
|
+
# representing `self`:
|
1703
|
+
#
|
1704
|
+
# require 'json/add/regexp'
|
1705
|
+
# x = /foo/.as_json
|
1706
|
+
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
1707
|
+
#
|
1708
|
+
# Method `JSON.create` deserializes such a hash, returning a Regexp object:
|
1709
|
+
#
|
1710
|
+
# Regexp.json_create(x) # => /foo/
|
1711
|
+
#
|
1712
|
+
def as_json: (*untyped) -> Hash[String, String | Integer]
|
1713
|
+
|
1714
|
+
# <!--
|
1715
|
+
# rdoc-file=ext/json/lib/json/add/regexp.rb
|
1716
|
+
# - to_json(*args)
|
1717
|
+
# -->
|
1718
|
+
# Returns a JSON string representing `self`:
|
1719
|
+
#
|
1720
|
+
# require 'json/add/regexp'
|
1721
|
+
# puts /foo/.to_json
|
1722
|
+
#
|
1723
|
+
# Output:
|
1724
|
+
#
|
1725
|
+
# {"json_class":"Regexp","o":0,"s":"foo"}
|
1726
|
+
#
|
1727
|
+
def to_json: (?JSON::State state) -> String
|
1728
|
+
end
|
1729
|
+
|
1730
|
+
%a{annotate:rdoc:skip}
|
1731
|
+
class Set[unchecked out A]
|
1732
|
+
# <!--
|
1733
|
+
# rdoc-file=ext/json/lib/json/add/set.rb
|
1734
|
+
# - json_create(object)
|
1735
|
+
# -->
|
1736
|
+
# See #as_json.
|
1737
|
+
#
|
1738
|
+
def self.json_create: [A] (Hash[String, String | Array[A]] object) -> Set[A]
|
1739
|
+
|
1740
|
+
# <!--
|
1741
|
+
# rdoc-file=ext/json/lib/json/add/set.rb
|
1742
|
+
# - as_json(*)
|
1743
|
+
# -->
|
1744
|
+
# Methods `Set#as_json` and `Set.json_create` may be used to serialize and
|
1745
|
+
# deserialize a Set object; see [Marshal](rdoc-ref:Marshal).
|
1746
|
+
#
|
1747
|
+
# Method `Set#as_json` serializes `self`, returning a 2-element hash
|
1748
|
+
# representing `self`:
|
1749
|
+
#
|
1750
|
+
# require 'json/add/set'
|
1751
|
+
# x = Set.new(%w/foo bar baz/).as_json
|
1752
|
+
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
1753
|
+
#
|
1754
|
+
# Method `JSON.create` deserializes such a hash, returning a Set object:
|
1755
|
+
#
|
1756
|
+
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
1757
|
+
#
|
1758
|
+
def as_json: (*untyped) -> Hash[String, String | Array[A]]
|
1759
|
+
|
1760
|
+
# <!--
|
1761
|
+
# rdoc-file=ext/json/lib/json/add/set.rb
|
1762
|
+
# - to_json(*args)
|
1763
|
+
# -->
|
1764
|
+
# Returns a JSON string representing `self`:
|
1765
|
+
#
|
1766
|
+
# require 'json/add/set'
|
1767
|
+
# puts Set.new(%w/foo bar baz/).to_json
|
1768
|
+
#
|
1769
|
+
# Output:
|
1770
|
+
#
|
1771
|
+
# {"json_class":"Set","a":["foo","bar","baz"]}
|
1772
|
+
#
|
1773
|
+
def to_json: (?JSON::State state) -> String
|
1774
|
+
end
|
1775
|
+
|
1776
|
+
%a{annotate:rdoc:skip}
|
1777
|
+
class Struct[Elem]
|
1778
|
+
# <!--
|
1779
|
+
# rdoc-file=ext/json/lib/json/add/struct.rb
|
1780
|
+
# - json_create(object)
|
1781
|
+
# -->
|
1782
|
+
# See #as_json.
|
1783
|
+
#
|
1784
|
+
def self.json_create: [Elem] (Hash[String, String | Array[Elem]] object) -> Struct[Elem]
|
1785
|
+
|
1786
|
+
# <!--
|
1787
|
+
# rdoc-file=ext/json/lib/json/add/struct.rb
|
1788
|
+
# - as_json(*)
|
1789
|
+
# -->
|
1790
|
+
# Methods `Struct#as_json` and `Struct.json_create` may be used to serialize and
|
1791
|
+
# deserialize a Struct object; see [Marshal](rdoc-ref:Marshal).
|
1792
|
+
#
|
1793
|
+
# Method `Struct#as_json` serializes `self`, returning a 2-element hash
|
1794
|
+
# representing `self`:
|
1795
|
+
#
|
1796
|
+
# require 'json/add/struct'
|
1797
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
1798
|
+
# x = Struct::Customer.new.as_json
|
1799
|
+
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
1800
|
+
#
|
1801
|
+
# Method `JSON.create` deserializes such a hash, returning a Struct object:
|
1802
|
+
#
|
1803
|
+
# Struct::Customer.json_create(x)
|
1804
|
+
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
1805
|
+
#
|
1806
|
+
def as_json: (*untyped) -> Hash[String, String | Array[Elem]]
|
1807
|
+
|
1808
|
+
# <!--
|
1809
|
+
# rdoc-file=ext/json/lib/json/add/struct.rb
|
1810
|
+
# - to_json(*args)
|
1811
|
+
# -->
|
1812
|
+
# Returns a JSON string representing `self`:
|
1813
|
+
#
|
1814
|
+
# require 'json/add/struct'
|
1815
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
1816
|
+
# puts Struct::Customer.new.to_json
|
1817
|
+
#
|
1818
|
+
# Output:
|
1819
|
+
#
|
1820
|
+
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
1821
|
+
#
|
1822
|
+
def to_json: (?JSON::State state) -> String
|
1823
|
+
end
|
1824
|
+
|
1825
|
+
%a{annotate:rdoc:skip}
|
1826
|
+
class Symbol
|
1827
|
+
# <!--
|
1828
|
+
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
1829
|
+
# - json_create(o)
|
1830
|
+
# -->
|
1831
|
+
# See #as_json.
|
1832
|
+
#
|
1833
|
+
def self.json_create: (Hash[String, String] object) -> instance
|
1834
|
+
|
1835
|
+
# <!--
|
1836
|
+
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
1837
|
+
# - as_json(*)
|
1838
|
+
# -->
|
1839
|
+
# Methods `Symbol#as_json` and `Symbol.json_create` may be used to serialize and
|
1840
|
+
# deserialize a Symbol object; see [Marshal](rdoc-ref:Marshal).
|
1841
|
+
#
|
1842
|
+
# Method `Symbol#as_json` serializes `self`, returning a 2-element hash
|
1843
|
+
# representing `self`:
|
1844
|
+
#
|
1845
|
+
# require 'json/add/symbol'
|
1846
|
+
# x = :foo.as_json
|
1847
|
+
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
1848
|
+
#
|
1849
|
+
# Method `JSON.create` deserializes such a hash, returning a Symbol object:
|
1850
|
+
#
|
1851
|
+
# Symbol.json_create(x) # => :foo
|
1852
|
+
#
|
1853
|
+
def as_json: (*untyped) -> Hash[String, String]
|
1854
|
+
|
1855
|
+
# <!--
|
1856
|
+
# rdoc-file=ext/json/lib/json/add/symbol.rb
|
1857
|
+
# - to_json(*a)
|
1858
|
+
# -->
|
1859
|
+
# Returns a JSON string representing `self`:
|
1860
|
+
#
|
1861
|
+
# require 'json/add/symbol'
|
1862
|
+
# puts :foo.to_json
|
1863
|
+
#
|
1864
|
+
# Output:
|
1865
|
+
#
|
1866
|
+
# # {"json_class":"Symbol","s":"foo"}
|
1867
|
+
#
|
1868
|
+
def to_json: (?JSON::State state) -> String
|
1869
|
+
end
|
1870
|
+
|
1871
|
+
%a{annotate:rdoc:skip}
|
1872
|
+
class Time
|
1873
|
+
# <!--
|
1874
|
+
# rdoc-file=ext/json/lib/json/add/time.rb
|
1875
|
+
# - json_create(object)
|
1876
|
+
# -->
|
1877
|
+
# See #as_json.
|
1878
|
+
#
|
1879
|
+
def self.json_create: (Hash[String, String | Integer] object) -> instance
|
1880
|
+
|
1881
|
+
# <!--
|
1882
|
+
# rdoc-file=ext/json/lib/json/add/time.rb
|
1883
|
+
# - as_json(*)
|
1884
|
+
# -->
|
1885
|
+
# Methods `Time#as_json` and `Time.json_create` may be used to serialize and
|
1886
|
+
# deserialize a Time object; see [Marshal](rdoc-ref:Marshal).
|
1887
|
+
#
|
1888
|
+
# Method `Time#as_json` serializes `self`, returning a 2-element hash
|
1889
|
+
# representing `self`:
|
1890
|
+
#
|
1891
|
+
# require 'json/add/time'
|
1892
|
+
# x = Time.now.as_json
|
1893
|
+
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
1894
|
+
#
|
1895
|
+
# Method `JSON.create` deserializes such a hash, returning a Time object:
|
1896
|
+
#
|
1897
|
+
# Time.json_create(x)
|
1898
|
+
# # => 2023-11-25 11:00:56.472846644 -0600
|
1899
|
+
#
|
1900
|
+
def as_json: (*untyped) -> Hash[String, String | Integer]
|
1901
|
+
|
1902
|
+
# <!--
|
1903
|
+
# rdoc-file=ext/json/lib/json/add/time.rb
|
1904
|
+
# - to_json(*args)
|
1905
|
+
# -->
|
1906
|
+
# Returns a JSON string representing `self`:
|
1907
|
+
#
|
1908
|
+
# require 'json/add/time'
|
1909
|
+
# puts Time.now.to_json
|
1910
|
+
#
|
1911
|
+
# Output:
|
1912
|
+
#
|
1913
|
+
# {"json_class":"Time","s":1700931678,"n":980650786}
|
1914
|
+
#
|
1915
|
+
def to_json: (?JSON::State state) -> String
|
1916
|
+
end
|