rbs 4.1.0.pre.2-java

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