rbs 4.1.0-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 (569) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.dockerignore +37 -0
  5. data/.github/dependabot.yml +24 -0
  6. data/.github/workflows/bundle-update.yml +63 -0
  7. data/.github/workflows/c-check.yml +66 -0
  8. data/.github/workflows/comments.yml +37 -0
  9. data/.github/workflows/dependabot.yml +30 -0
  10. data/.github/workflows/jruby.yml +79 -0
  11. data/.github/workflows/milestone.yml +91 -0
  12. data/.github/workflows/ruby.yml +158 -0
  13. data/.github/workflows/rust.yml +186 -0
  14. data/.github/workflows/truffleruby.yml +54 -0
  15. data/.github/workflows/typecheck.yml +39 -0
  16. data/.github/workflows/wasm.yml +55 -0
  17. data/.github/workflows/windows.yml +49 -0
  18. data/.gitignore +39 -0
  19. data/.rubocop.yml +72 -0
  20. data/BSDL +22 -0
  21. data/CHANGELOG.md +2380 -0
  22. data/COPYING +56 -0
  23. data/Dockerfile.jruby +53 -0
  24. data/README.md +240 -0
  25. data/Rakefile +856 -0
  26. data/Steepfile +55 -0
  27. data/config.yml +913 -0
  28. data/core/array.rbs +4205 -0
  29. data/core/basic_object.rbs +376 -0
  30. data/core/binding.rbs +148 -0
  31. data/core/builtin.rbs +278 -0
  32. data/core/class.rbs +223 -0
  33. data/core/comparable.rbs +192 -0
  34. data/core/complex.rbs +812 -0
  35. data/core/constants.rbs +96 -0
  36. data/core/data.rbs +415 -0
  37. data/core/dir.rbs +993 -0
  38. data/core/encoding.rbs +1368 -0
  39. data/core/enumerable.rbs +2506 -0
  40. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  41. data/core/enumerator/product.rbs +92 -0
  42. data/core/enumerator.rbs +705 -0
  43. data/core/env.rbs +6 -0
  44. data/core/errno.rbs +682 -0
  45. data/core/errors.rbs +789 -0
  46. data/core/exception.rbs +485 -0
  47. data/core/false_class.rbs +82 -0
  48. data/core/fiber.rbs +570 -0
  49. data/core/fiber_error.rbs +11 -0
  50. data/core/file.rbs +2045 -0
  51. data/core/file_constants.rbs +463 -0
  52. data/core/file_stat.rbs +534 -0
  53. data/core/file_test.rbs +331 -0
  54. data/core/float.rbs +1292 -0
  55. data/core/gc.rbs +788 -0
  56. data/core/global_variables.rbs +184 -0
  57. data/core/hash.rbs +2183 -0
  58. data/core/integer.rbs +1374 -0
  59. data/core/io/buffer.rbs +995 -0
  60. data/core/io/wait.rbs +48 -0
  61. data/core/io.rbs +3472 -0
  62. data/core/kernel.rbs +3172 -0
  63. data/core/marshal.rbs +207 -0
  64. data/core/match_data.rbs +637 -0
  65. data/core/math.rbs +770 -0
  66. data/core/method.rbs +422 -0
  67. data/core/module.rbs +1856 -0
  68. data/core/nil_class.rbs +210 -0
  69. data/core/numeric.rbs +832 -0
  70. data/core/object.rbs +108 -0
  71. data/core/object_space/weak_key_map.rbs +166 -0
  72. data/core/object_space.rbs +197 -0
  73. data/core/pathname.rbs +1312 -0
  74. data/core/proc.rbs +905 -0
  75. data/core/process.rbs +2316 -0
  76. data/core/ractor.rbs +914 -0
  77. data/core/random.rbs +255 -0
  78. data/core/range.rbs +1209 -0
  79. data/core/rational.rbs +502 -0
  80. data/core/rb_config.rbs +88 -0
  81. data/core/rbs/ops.rbs +154 -0
  82. data/core/rbs/unnamed/argf.rbs +1236 -0
  83. data/core/rbs/unnamed/env_class.rbs +1214 -0
  84. data/core/rbs/unnamed/main_class.rbs +123 -0
  85. data/core/rbs/unnamed/random.rbs +186 -0
  86. data/core/refinement.rbs +59 -0
  87. data/core/regexp.rbs +1974 -0
  88. data/core/ruby.rbs +53 -0
  89. data/core/ruby_vm.rbs +809 -0
  90. data/core/rubygems/basic_specification.rbs +6 -0
  91. data/core/rubygems/config_file.rbs +38 -0
  92. data/core/rubygems/dependency_installer.rbs +6 -0
  93. data/core/rubygems/errors.rbs +112 -0
  94. data/core/rubygems/installer.rbs +15 -0
  95. data/core/rubygems/path_support.rbs +6 -0
  96. data/core/rubygems/platform.rbs +7 -0
  97. data/core/rubygems/request_set.rbs +49 -0
  98. data/core/rubygems/requirement.rbs +138 -0
  99. data/core/rubygems/rubygems.rbs +1108 -0
  100. data/core/rubygems/source_list.rbs +15 -0
  101. data/core/rubygems/specification.rbs +31 -0
  102. data/core/rubygems/stream_ui.rbs +5 -0
  103. data/core/rubygems/uninstaller.rbs +10 -0
  104. data/core/rubygems/version.rbs +133 -0
  105. data/core/set.rbs +751 -0
  106. data/core/signal.rbs +110 -0
  107. data/core/string.rbs +5532 -0
  108. data/core/struct.rbs +668 -0
  109. data/core/symbol.rbs +482 -0
  110. data/core/thread.rbs +1821 -0
  111. data/core/thread_group.rbs +79 -0
  112. data/core/time.rbs +1793 -0
  113. data/core/trace_point.rbs +483 -0
  114. data/core/true_class.rbs +98 -0
  115. data/core/unbound_method.rbs +337 -0
  116. data/core/warning.rbs +87 -0
  117. data/docs/CONTRIBUTING.md +107 -0
  118. data/docs/aliases.md +79 -0
  119. data/docs/architecture.md +110 -0
  120. data/docs/collection.md +192 -0
  121. data/docs/config.md +171 -0
  122. data/docs/data_and_struct.md +86 -0
  123. data/docs/encoding.md +56 -0
  124. data/docs/gem.md +56 -0
  125. data/docs/inline.md +634 -0
  126. data/docs/rbs_by_example.md +309 -0
  127. data/docs/release.md +69 -0
  128. data/docs/repo.md +125 -0
  129. data/docs/rust.md +96 -0
  130. data/docs/sigs.md +167 -0
  131. data/docs/stdlib.md +147 -0
  132. data/docs/syntax.md +940 -0
  133. data/docs/tools.md +17 -0
  134. data/docs/type_fingerprint.md +21 -0
  135. data/docs/wasm_serialization.md +80 -0
  136. data/exe/rbs +7 -0
  137. data/ext/rbs_extension/ast_translation.c +1855 -0
  138. data/ext/rbs_extension/ast_translation.h +41 -0
  139. data/ext/rbs_extension/class_constants.c +187 -0
  140. data/ext/rbs_extension/class_constants.h +104 -0
  141. data/ext/rbs_extension/compat.h +10 -0
  142. data/ext/rbs_extension/extconf.rb +40 -0
  143. data/ext/rbs_extension/legacy_location.c +299 -0
  144. data/ext/rbs_extension/legacy_location.h +82 -0
  145. data/ext/rbs_extension/main.c +613 -0
  146. data/ext/rbs_extension/rbs_extension.h +16 -0
  147. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  148. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  149. data/goodcheck.yml +91 -0
  150. data/include/rbs/ast.h +1047 -0
  151. data/include/rbs/defines.h +99 -0
  152. data/include/rbs/lexer.h +207 -0
  153. data/include/rbs/location.h +40 -0
  154. data/include/rbs/parser.h +153 -0
  155. data/include/rbs/serialize.h +39 -0
  156. data/include/rbs/string.h +47 -0
  157. data/include/rbs/util/rbs_allocator.h +59 -0
  158. data/include/rbs/util/rbs_assert.h +20 -0
  159. data/include/rbs/util/rbs_buffer.h +83 -0
  160. data/include/rbs/util/rbs_constant_pool.h +155 -0
  161. data/include/rbs/util/rbs_encoding.h +282 -0
  162. data/include/rbs/util/rbs_unescape.h +24 -0
  163. data/include/rbs.h +14 -0
  164. data/lib/rbs/ancestor_graph.rb +92 -0
  165. data/lib/rbs/annotate/annotations.rb +199 -0
  166. data/lib/rbs/annotate/formatter.rb +82 -0
  167. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  168. data/lib/rbs/annotate/rdoc_source.rb +131 -0
  169. data/lib/rbs/annotate.rb +8 -0
  170. data/lib/rbs/ast/annotation.rb +29 -0
  171. data/lib/rbs/ast/comment.rb +29 -0
  172. data/lib/rbs/ast/declarations.rb +472 -0
  173. data/lib/rbs/ast/directives.rb +49 -0
  174. data/lib/rbs/ast/members.rb +451 -0
  175. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  176. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  177. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  178. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  179. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  180. data/lib/rbs/ast/ruby/members.rb +762 -0
  181. data/lib/rbs/ast/type_param.rb +235 -0
  182. data/lib/rbs/ast/visitor.rb +137 -0
  183. data/lib/rbs/buffer.rb +189 -0
  184. data/lib/rbs/builtin_names.rb +58 -0
  185. data/lib/rbs/cli/colored_io.rb +48 -0
  186. data/lib/rbs/cli/diff.rb +84 -0
  187. data/lib/rbs/cli/validate.rb +294 -0
  188. data/lib/rbs/cli.rb +1253 -0
  189. data/lib/rbs/collection/cleaner.rb +38 -0
  190. data/lib/rbs/collection/config/lockfile.rb +92 -0
  191. data/lib/rbs/collection/config/lockfile_generator.rb +269 -0
  192. data/lib/rbs/collection/config.rb +81 -0
  193. data/lib/rbs/collection/installer.rb +32 -0
  194. data/lib/rbs/collection/sources/base.rb +14 -0
  195. data/lib/rbs/collection/sources/git.rb +265 -0
  196. data/lib/rbs/collection/sources/local.rb +81 -0
  197. data/lib/rbs/collection/sources/rubygems.rb +48 -0
  198. data/lib/rbs/collection/sources/stdlib.rb +50 -0
  199. data/lib/rbs/collection/sources.rb +38 -0
  200. data/lib/rbs/collection.rb +16 -0
  201. data/lib/rbs/constant.rb +28 -0
  202. data/lib/rbs/definition.rb +415 -0
  203. data/lib/rbs/definition_builder/ancestor_builder.rb +678 -0
  204. data/lib/rbs/definition_builder/method_builder.rb +295 -0
  205. data/lib/rbs/definition_builder.rb +1054 -0
  206. data/lib/rbs/diff.rb +131 -0
  207. data/lib/rbs/environment/class_entry.rb +69 -0
  208. data/lib/rbs/environment/module_entry.rb +66 -0
  209. data/lib/rbs/environment/use_map.rb +77 -0
  210. data/lib/rbs/environment.rb +1028 -0
  211. data/lib/rbs/environment_loader.rb +167 -0
  212. data/lib/rbs/environment_walker.rb +155 -0
  213. data/lib/rbs/errors.rb +634 -0
  214. data/lib/rbs/factory.rb +18 -0
  215. data/lib/rbs/file_finder.rb +28 -0
  216. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  217. data/lib/rbs/inline_parser.rb +568 -0
  218. data/lib/rbs/location_aux.rb +170 -0
  219. data/lib/rbs/locator.rb +247 -0
  220. data/lib/rbs/method_type.rb +145 -0
  221. data/lib/rbs/namespace.rb +154 -0
  222. data/lib/rbs/parser/lex_result.rb +15 -0
  223. data/lib/rbs/parser/token.rb +23 -0
  224. data/lib/rbs/parser_aux.rb +144 -0
  225. data/lib/rbs/prototype/helpers.rb +197 -0
  226. data/lib/rbs/prototype/node_usage.rb +99 -0
  227. data/lib/rbs/prototype/rb.rb +816 -0
  228. data/lib/rbs/prototype/rbi.rb +793 -0
  229. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  230. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  231. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  232. data/lib/rbs/prototype/runtime.rb +680 -0
  233. data/lib/rbs/repository.rb +127 -0
  234. data/lib/rbs/resolver/constant_resolver.rb +219 -0
  235. data/lib/rbs/resolver/type_name_resolver.rb +167 -0
  236. data/lib/rbs/rewriter.rb +70 -0
  237. data/lib/rbs/sorter.rb +198 -0
  238. data/lib/rbs/source.rb +99 -0
  239. data/lib/rbs/substitution.rb +83 -0
  240. data/lib/rbs/subtractor.rb +204 -0
  241. data/lib/rbs/test/errors.rb +80 -0
  242. data/lib/rbs/test/guaranteed.rb +30 -0
  243. data/lib/rbs/test/hook.rb +212 -0
  244. data/lib/rbs/test/observer.rb +19 -0
  245. data/lib/rbs/test/setup.rb +84 -0
  246. data/lib/rbs/test/setup_helper.rb +50 -0
  247. data/lib/rbs/test/tester.rb +167 -0
  248. data/lib/rbs/test/type_check.rb +457 -0
  249. data/lib/rbs/test.rb +112 -0
  250. data/lib/rbs/type_alias_dependency.rb +100 -0
  251. data/lib/rbs/type_alias_regularity.rb +126 -0
  252. data/lib/rbs/type_name.rb +122 -0
  253. data/lib/rbs/types.rb +1604 -0
  254. data/lib/rbs/unit_test/convertibles.rb +177 -0
  255. data/lib/rbs/unit_test/spy.rb +138 -0
  256. data/lib/rbs/unit_test/type_assertions.rb +383 -0
  257. data/lib/rbs/unit_test/with_aliases.rb +145 -0
  258. data/lib/rbs/unit_test.rb +6 -0
  259. data/lib/rbs/validator.rb +186 -0
  260. data/lib/rbs/variance_calculator.rb +189 -0
  261. data/lib/rbs/vendorer.rb +71 -0
  262. data/lib/rbs/version.rb +5 -0
  263. data/lib/rbs/wasm/deserializer.rb +213 -0
  264. data/lib/rbs/wasm/location.rb +61 -0
  265. data/lib/rbs/wasm/parser.rb +137 -0
  266. data/lib/rbs/wasm/rbs_parser.wasm +0 -0
  267. data/lib/rbs/wasm/runtime.rb +196 -0
  268. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  269. data/lib/rbs/writer.rb +424 -0
  270. data/lib/rbs.rb +117 -0
  271. data/lib/rbs_jars.rb +39 -0
  272. data/lib/rdoc/discover.rb +20 -0
  273. data/lib/rdoc_plugin/parser.rb +168 -0
  274. data/rbs.gemspec +81 -0
  275. data/schema/annotation.json +14 -0
  276. data/schema/comment.json +26 -0
  277. data/schema/decls.json +326 -0
  278. data/schema/function.json +87 -0
  279. data/schema/location.json +56 -0
  280. data/schema/members.json +266 -0
  281. data/schema/methodType.json +50 -0
  282. data/schema/typeParam.json +52 -0
  283. data/schema/types.json +317 -0
  284. data/sig/ancestor_builder.rbs +163 -0
  285. data/sig/ancestor_graph.rbs +60 -0
  286. data/sig/annotate/annotations.rbs +102 -0
  287. data/sig/annotate/formatter.rbs +24 -0
  288. data/sig/annotate/rdoc_annotater.rbs +85 -0
  289. data/sig/annotate/rdoc_source.rbs +32 -0
  290. data/sig/annotation.rbs +27 -0
  291. data/sig/ast/ruby/annotations.rbs +470 -0
  292. data/sig/ast/ruby/comment_block.rbs +127 -0
  293. data/sig/ast/ruby/declarations.rbs +158 -0
  294. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  295. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  296. data/sig/ast/ruby/members.rbs +198 -0
  297. data/sig/buffer.rbs +108 -0
  298. data/sig/builtin_names.rbs +44 -0
  299. data/sig/cli/colored_io.rbs +15 -0
  300. data/sig/cli/diff.rbs +15 -0
  301. data/sig/cli/validate.rbs +47 -0
  302. data/sig/cli.rbs +89 -0
  303. data/sig/collection/cleaner.rbs +13 -0
  304. data/sig/collection/config/lockfile.rbs +74 -0
  305. data/sig/collection/config/lockfile_generator.rbs +68 -0
  306. data/sig/collection/config.rbs +46 -0
  307. data/sig/collection/installer.rbs +17 -0
  308. data/sig/collection/sources.rbs +214 -0
  309. data/sig/collection.rbs +4 -0
  310. data/sig/comment.rbs +26 -0
  311. data/sig/constant.rbs +21 -0
  312. data/sig/declarations.rbs +274 -0
  313. data/sig/definition.rbs +232 -0
  314. data/sig/definition_builder.rbs +181 -0
  315. data/sig/diff.rbs +28 -0
  316. data/sig/directives.rbs +77 -0
  317. data/sig/environment/class_entry.rbs +50 -0
  318. data/sig/environment/module_entry.rbs +50 -0
  319. data/sig/environment.rbs +286 -0
  320. data/sig/environment_loader.rbs +111 -0
  321. data/sig/environment_walker.rbs +65 -0
  322. data/sig/errors.rbs +408 -0
  323. data/sig/factory.rbs +5 -0
  324. data/sig/file_finder.rbs +28 -0
  325. data/sig/inline_parser/comment_association.rbs +71 -0
  326. data/sig/inline_parser.rbs +126 -0
  327. data/sig/location.rbs +135 -0
  328. data/sig/locator.rbs +56 -0
  329. data/sig/manifest.yaml +5 -0
  330. data/sig/members.rbs +258 -0
  331. data/sig/method_builder.rbs +89 -0
  332. data/sig/method_types.rbs +58 -0
  333. data/sig/namespace.rbs +161 -0
  334. data/sig/parser.rbs +164 -0
  335. data/sig/prototype/helpers.rbs +29 -0
  336. data/sig/prototype/node_usage.rbs +20 -0
  337. data/sig/prototype/rb.rbs +96 -0
  338. data/sig/prototype/rbi.rbs +104 -0
  339. data/sig/prototype/runtime.rbs +182 -0
  340. data/sig/rbs.rbs +21 -0
  341. data/sig/rdoc/rbs.rbs +67 -0
  342. data/sig/repository.rbs +85 -0
  343. data/sig/resolver/constant_resolver.rbs +92 -0
  344. data/sig/resolver/context.rbs +34 -0
  345. data/sig/resolver/type_name_resolver.rbs +61 -0
  346. data/sig/rewriter.rbs +45 -0
  347. data/sig/shims/bundler.rbs +38 -0
  348. data/sig/shims/enumerable.rbs +5 -0
  349. data/sig/shims/rubygems.rbs +19 -0
  350. data/sig/sorter.rbs +41 -0
  351. data/sig/source.rbs +48 -0
  352. data/sig/substitution.rbs +48 -0
  353. data/sig/subtractor.rbs +37 -0
  354. data/sig/test/errors.rbs +52 -0
  355. data/sig/test/guranteed.rbs +9 -0
  356. data/sig/test/type_check.rbs +19 -0
  357. data/sig/test.rbs +82 -0
  358. data/sig/type_alias_dependency.rbs +53 -0
  359. data/sig/type_alias_regularity.rbs +98 -0
  360. data/sig/type_param.rbs +115 -0
  361. data/sig/typename.rbs +89 -0
  362. data/sig/types.rbs +578 -0
  363. data/sig/unit_test/convertibles.rbs +154 -0
  364. data/sig/unit_test/spy.rbs +22 -0
  365. data/sig/unit_test/type_assertions.rbs +211 -0
  366. data/sig/unit_test/with_aliases.rbs +136 -0
  367. data/sig/use_map.rbs +35 -0
  368. data/sig/util.rbs +9 -0
  369. data/sig/validator.rbs +63 -0
  370. data/sig/variance_calculator.rbs +87 -0
  371. data/sig/vendorer.rbs +51 -0
  372. data/sig/version.rbs +3 -0
  373. data/sig/visitor.rbs +47 -0
  374. data/sig/wasm/deserializer.rbs +66 -0
  375. data/sig/wasm/serialization_schema.rbs +13 -0
  376. data/sig/writer.rbs +127 -0
  377. data/src/ast.c +1628 -0
  378. data/src/lexer.c +3221 -0
  379. data/src/lexer.re +155 -0
  380. data/src/lexstate.c +221 -0
  381. data/src/location.c +31 -0
  382. data/src/parser.c +4255 -0
  383. data/src/serialize.c +958 -0
  384. data/src/string.c +41 -0
  385. data/src/util/rbs_allocator.c +171 -0
  386. data/src/util/rbs_assert.c +19 -0
  387. data/src/util/rbs_buffer.c +54 -0
  388. data/src/util/rbs_constant_pool.c +268 -0
  389. data/src/util/rbs_encoding.c +21308 -0
  390. data/src/util/rbs_unescape.c +167 -0
  391. data/stdlib/abbrev/0/abbrev.rbs +66 -0
  392. data/stdlib/abbrev/0/array.rbs +26 -0
  393. data/stdlib/base64/0/base64.rbs +355 -0
  394. data/stdlib/benchmark/0/benchmark.rbs +452 -0
  395. data/stdlib/bigdecimal/0/big_decimal.rbs +1647 -0
  396. data/stdlib/bigdecimal-math/0/big_math.rbs +280 -0
  397. data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
  398. data/stdlib/cgi/0/core.rbs +911 -0
  399. data/stdlib/cgi/0/manifest.yaml +4 -0
  400. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  401. data/stdlib/coverage/0/coverage.rbs +266 -0
  402. data/stdlib/csv/0/csv.rbs +3776 -0
  403. data/stdlib/csv/0/manifest.yaml +3 -0
  404. data/stdlib/date/0/date.rbs +1598 -0
  405. data/stdlib/date/0/date_time.rbs +617 -0
  406. data/stdlib/date/0/time.rbs +26 -0
  407. data/stdlib/dbm/0/dbm.rbs +421 -0
  408. data/stdlib/delegate/0/delegator.rbs +188 -0
  409. data/stdlib/delegate/0/kernel.rbs +47 -0
  410. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  411. data/stdlib/did_you_mean/0/did_you_mean.rbs +344 -0
  412. data/stdlib/digest/0/digest.rbs +693 -0
  413. data/stdlib/erb/0/erb.rbs +933 -0
  414. data/stdlib/etc/0/etc.rbs +884 -0
  415. data/stdlib/fileutils/0/fileutils.rbs +1753 -0
  416. data/stdlib/find/0/find.rbs +49 -0
  417. data/stdlib/forwardable/0/forwardable.rbs +271 -0
  418. data/stdlib/io-console/0/io-console.rbs +414 -0
  419. data/stdlib/ipaddr/0/ipaddr.rbs +431 -0
  420. data/stdlib/json/0/json.rbs +1963 -0
  421. data/stdlib/kconv/0/kconv.rbs +166 -0
  422. data/stdlib/logger/0/formatter.rbs +45 -0
  423. data/stdlib/logger/0/log_device.rbs +100 -0
  424. data/stdlib/logger/0/logger.rbs +796 -0
  425. data/stdlib/logger/0/manifest.yaml +2 -0
  426. data/stdlib/logger/0/period.rbs +17 -0
  427. data/stdlib/logger/0/severity.rbs +34 -0
  428. data/stdlib/minitest/0/kernel.rbs +42 -0
  429. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
  430. data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
  431. data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
  432. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
  433. data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
  434. data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
  435. data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
  436. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  437. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  438. data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
  439. data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
  440. data/stdlib/minitest/0/minitest/guard.rbs +64 -0
  441. data/stdlib/minitest/0/minitest/mock.rbs +64 -0
  442. data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
  443. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
  444. data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
  445. data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
  446. data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
  447. data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
  448. data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
  449. data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
  450. data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
  451. data/stdlib/minitest/0/minitest/result.rbs +28 -0
  452. data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
  453. data/stdlib/minitest/0/minitest/skip.rbs +6 -0
  454. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
  455. data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
  456. data/stdlib/minitest/0/minitest/spec.rbs +11 -0
  457. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
  458. data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
  459. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
  460. data/stdlib/minitest/0/minitest/test.rbs +69 -0
  461. data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
  462. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  463. data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
  464. data/stdlib/minitest/0/minitest/unit.rbs +4 -0
  465. data/stdlib/minitest/0/minitest.rbs +115 -0
  466. data/stdlib/monitor/0/monitor.rbs +363 -0
  467. data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
  468. data/stdlib/net-http/0/manifest.yaml +3 -0
  469. data/stdlib/net-http/0/net-http.rbs +5580 -0
  470. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  471. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  472. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  473. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  474. data/stdlib/nkf/0/nkf.rbs +402 -0
  475. data/stdlib/objspace/0/objspace.rbs +470 -0
  476. data/stdlib/observable/0/observable.rbs +217 -0
  477. data/stdlib/open-uri/0/manifest.yaml +4 -0
  478. data/stdlib/open-uri/0/open-uri.rbs +433 -0
  479. data/stdlib/open3/0/open3.rbs +606 -0
  480. data/stdlib/openssl/0/manifest.yaml +3 -0
  481. data/stdlib/openssl/0/openssl.rbs +12237 -0
  482. data/stdlib/optparse/0/optparse.rbs +1734 -0
  483. data/stdlib/pathname/0/pathname.rbs +36 -0
  484. data/stdlib/pp/0/manifest.yaml +2 -0
  485. data/stdlib/pp/0/pp.rbs +301 -0
  486. data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
  487. data/stdlib/pstore/0/pstore.rbs +608 -0
  488. data/stdlib/psych/0/core_ext.rbs +12 -0
  489. data/stdlib/psych/0/dbm.rbs +237 -0
  490. data/stdlib/psych/0/manifest.yaml +3 -0
  491. data/stdlib/psych/0/psych.rbs +455 -0
  492. data/stdlib/psych/0/store.rbs +57 -0
  493. data/stdlib/pty/0/pty.rbs +240 -0
  494. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  495. data/stdlib/rdoc/0/code_object.rbs +52 -0
  496. data/stdlib/rdoc/0/comment.rbs +61 -0
  497. data/stdlib/rdoc/0/context.rbs +153 -0
  498. data/stdlib/rdoc/0/markup.rbs +117 -0
  499. data/stdlib/rdoc/0/options.rbs +76 -0
  500. data/stdlib/rdoc/0/parser.rbs +56 -0
  501. data/stdlib/rdoc/0/rdoc.rbs +393 -0
  502. data/stdlib/rdoc/0/ri.rbs +17 -0
  503. data/stdlib/rdoc/0/store.rbs +48 -0
  504. data/stdlib/rdoc/0/top_level.rbs +97 -0
  505. data/stdlib/resolv/0/manifest.yaml +3 -0
  506. data/stdlib/resolv/0/resolv.rbs +1787 -0
  507. data/stdlib/ripper/0/ripper.rbs +1654 -0
  508. data/stdlib/securerandom/0/manifest.yaml +2 -0
  509. data/stdlib/securerandom/0/securerandom.rbs +49 -0
  510. data/stdlib/shellwords/0/shellwords.rbs +229 -0
  511. data/stdlib/singleton/0/singleton.rbs +134 -0
  512. data/stdlib/socket/0/addrinfo.rbs +666 -0
  513. data/stdlib/socket/0/basic_socket.rbs +590 -0
  514. data/stdlib/socket/0/constants.rbs +2295 -0
  515. data/stdlib/socket/0/ip_socket.rbs +94 -0
  516. data/stdlib/socket/0/socket.rbs +4170 -0
  517. data/stdlib/socket/0/socket_error.rbs +5 -0
  518. data/stdlib/socket/0/tcp_server.rbs +192 -0
  519. data/stdlib/socket/0/tcp_socket.rbs +87 -0
  520. data/stdlib/socket/0/udp_socket.rbs +133 -0
  521. data/stdlib/socket/0/unix_server.rbs +169 -0
  522. data/stdlib/socket/0/unix_socket.rbs +172 -0
  523. data/stdlib/stringio/0/stringio.rbs +1681 -0
  524. data/stdlib/strscan/0/string_scanner.rbs +1648 -0
  525. data/stdlib/tempfile/0/manifest.yaml +3 -0
  526. data/stdlib/tempfile/0/tempfile.rbs +483 -0
  527. data/stdlib/time/0/time.rbs +434 -0
  528. data/stdlib/timeout/0/timeout.rbs +132 -0
  529. data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
  530. data/stdlib/tsort/0/cyclic.rbs +8 -0
  531. data/stdlib/tsort/0/interfaces.rbs +20 -0
  532. data/stdlib/tsort/0/tsort.rbs +410 -0
  533. data/stdlib/uri/0/common.rbs +621 -0
  534. data/stdlib/uri/0/file.rbs +118 -0
  535. data/stdlib/uri/0/ftp.rbs +13 -0
  536. data/stdlib/uri/0/generic.rbs +1111 -0
  537. data/stdlib/uri/0/http.rbs +104 -0
  538. data/stdlib/uri/0/https.rbs +14 -0
  539. data/stdlib/uri/0/ldap.rbs +230 -0
  540. data/stdlib/uri/0/ldaps.rbs +14 -0
  541. data/stdlib/uri/0/mailto.rbs +92 -0
  542. data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
  543. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  544. data/stdlib/uri/0/ws.rbs +13 -0
  545. data/stdlib/uri/0/wss.rbs +9 -0
  546. data/stdlib/yaml/0/manifest.yaml +2 -0
  547. data/stdlib/yaml/0/yaml.rbs +1 -0
  548. data/stdlib/zlib/0/buf_error.rbs +10 -0
  549. data/stdlib/zlib/0/data_error.rbs +10 -0
  550. data/stdlib/zlib/0/deflate.rbs +211 -0
  551. data/stdlib/zlib/0/error.rbs +20 -0
  552. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  553. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  554. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  555. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  556. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  557. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  558. data/stdlib/zlib/0/gzip_writer.rbs +168 -0
  559. data/stdlib/zlib/0/inflate.rbs +180 -0
  560. data/stdlib/zlib/0/mem_error.rbs +10 -0
  561. data/stdlib/zlib/0/need_dict.rbs +13 -0
  562. data/stdlib/zlib/0/stream_end.rbs +11 -0
  563. data/stdlib/zlib/0/stream_error.rbs +11 -0
  564. data/stdlib/zlib/0/version_error.rbs +11 -0
  565. data/stdlib/zlib/0/zlib.rbs +449 -0
  566. data/stdlib/zlib/0/zstream.rbs +200 -0
  567. data/wasm/README.md +60 -0
  568. data/wasm/rbs_wasm.c +423 -0
  569. metadata +671 -0
data/core/array.rbs ADDED
@@ -0,0 +1,4205 @@
1
+ # <!-- rdoc-file=array.c -->
2
+ # An Array object is an ordered, integer-indexed collection of objects, called
3
+ # *elements*; the object represents an [array data
4
+ # structure](https://en.wikipedia.org/wiki/Array_(data_structure)).
5
+ #
6
+ # An element may be any object (even another array); elements may be any mixture
7
+ # of objects of different types.
8
+ #
9
+ # Important data structures that use arrays include:
10
+ #
11
+ # * [Coordinate vector](https://en.wikipedia.org/wiki/Coordinate_vector).
12
+ # * [Matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics)).
13
+ # * [Heap](https://en.wikipedia.org/wiki/Heap_(data_structure)).
14
+ # * [Hash table](https://en.wikipedia.org/wiki/Hash_table).
15
+ # * [Deque (double-ended
16
+ # queue)](https://en.wikipedia.org/wiki/Double-ended_queue).
17
+ # * [Queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)).
18
+ # * [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)).
19
+ #
20
+ # There are also array-like data structures:
21
+ #
22
+ # * [Associative array](https://en.wikipedia.org/wiki/Associative_array) (see
23
+ # Hash).
24
+ # * [Directory](https://en.wikipedia.org/wiki/Directory_(computing)) (see
25
+ # Dir).
26
+ # * [Environment](https://en.wikipedia.org/wiki/Environment_variable) (see
27
+ # ENV).
28
+ # * [Set](https://en.wikipedia.org/wiki/Set_(abstract_data_type)) (see Set).
29
+ # * [String](https://en.wikipedia.org/wiki/String_(computer_science)) (see
30
+ # String).
31
+ #
32
+ # ## Array Indexes
33
+ #
34
+ # Array indexing starts at 0, as in C or Java.
35
+ #
36
+ # A non-negative index is an offset from the first element:
37
+ #
38
+ # * Index 0 indicates the first element.
39
+ # * Index 1 indicates the second element.
40
+ # * ...
41
+ #
42
+ # A negative index is an offset, backwards, from the end of the array:
43
+ #
44
+ # * Index -1 indicates the last element.
45
+ # * Index -2 indicates the next-to-last element.
46
+ # * ...
47
+ #
48
+ # ### In-Range and Out-of-Range Indexes
49
+ #
50
+ # A non-negative index is *in range* if and only if it is smaller than the size
51
+ # of the array. For a 3-element array:
52
+ #
53
+ # * Indexes 0 through 2 are in range.
54
+ # * Index 3 is out of range.
55
+ #
56
+ # A negative index is *in range* if and only if its absolute value is not larger
57
+ # than the size of the array. For a 3-element array:
58
+ #
59
+ # * Indexes -1 through -3 are in range.
60
+ # * Index -4 is out of range.
61
+ #
62
+ # ### Effective Index
63
+ #
64
+ # Although the effective index into an array is always an integer, some methods
65
+ # (both within class Array and elsewhere) accept one or more non-integer
66
+ # arguments that are [integer-convertible
67
+ # objects](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
68
+ #
69
+ # ## Creating Arrays
70
+ #
71
+ # You can create an Array object explicitly with:
72
+ #
73
+ # * An [array literal](rdoc-ref:syntax/literals.rdoc@Array+Literals):
74
+ #
75
+ # [1, 'one', :one, [2, 'two', :two]]
76
+ #
77
+ # * A [%w or %W string-array
78
+ # Literal](rdoc-ref:syntax/literals.rdoc@25w+and+-25W-3A+String-Array+Litera
79
+ # ls):
80
+ #
81
+ # %w[foo bar baz] # => ["foo", "bar", "baz"]
82
+ # %w[1 % *] # => ["1", "%", "*"]
83
+ #
84
+ # * A [%i or %I symbol-array
85
+ # Literal](rdoc-ref:syntax/literals.rdoc@25i+and+-25I-3A+Symbol-Array+Litera
86
+ # ls):
87
+ #
88
+ # %i[foo bar baz] # => [:foo, :bar, :baz]
89
+ # %i[1 % *] # => [:"1", :%, :*]
90
+ #
91
+ # * Method Kernel#Array:
92
+ #
93
+ # Array(["a", "b"]) # => ["a", "b"]
94
+ # Array(1..5) # => [1, 2, 3, 4, 5]
95
+ # Array(key: :value) # => [[:key, :value]]
96
+ # Array(nil) # => []
97
+ # Array(1) # => [1]
98
+ # Array({:a => "a", :b => "b"}) # => [[:a, "a"], [:b, "b"]]
99
+ #
100
+ # * Method Array.new:
101
+ #
102
+ # Array.new # => []
103
+ # Array.new(3) # => [nil, nil, nil]
104
+ # Array.new(4) {Hash.new} # => [{}, {}, {}, {}]
105
+ # Array.new(3, true) # => [true, true, true]
106
+ #
107
+ # Note that the last example above populates the array with references to
108
+ # the same object. This is recommended only in cases where that object is a
109
+ # natively immutable object such as a symbol, a numeric, `nil`, `true`, or
110
+ # `false`.
111
+ #
112
+ # Another way to create an array with various objects, using a block; this
113
+ # usage is safe for mutable objects such as hashes, strings or other arrays:
114
+ #
115
+ # Array.new(4) {|i| i.to_s } # => ["0", "1", "2", "3"]
116
+ #
117
+ # Here is a way to create a multi-dimensional array:
118
+ #
119
+ # Array.new(3) {Array.new(3)}
120
+ # # => [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
121
+ #
122
+ # A number of Ruby methods, both in the core and in the standard library,
123
+ # provide instance method `to_a`, which converts an object to an array.
124
+ #
125
+ # * ARGF#to_a
126
+ # * Array#to_a
127
+ # * Enumerable#to_a
128
+ # * Hash#to_a
129
+ # * MatchData#to_a
130
+ # * NilClass#to_a
131
+ # * OptionParser#to_a
132
+ # * Range#to_a
133
+ # * Set#to_a
134
+ # * Struct#to_a
135
+ # * Time#to_a
136
+ # * Benchmark::Tms#to_a
137
+ # * CSV::Table#to_a
138
+ # * Enumerator::Lazy#to_a
139
+ # * Gem::List#to_a
140
+ # * Gem::NameTuple#to_a
141
+ # * Gem::Platform#to_a
142
+ # * Gem::RequestSet::Lockfile::Tokenizer#to_a
143
+ # * Gem::SourceList#to_a
144
+ # * OpenSSL::X509::Extension#to_a
145
+ # * OpenSSL::X509::Name#to_a
146
+ # * Racc::ISet#to_a
147
+ # * Rinda::RingFinger#to_a
148
+ # * Ripper::Lexer::Elem#to_a
149
+ # * RubyVM::InstructionSequence#to_a
150
+ # * YAML::DBM#to_a
151
+ #
152
+ # ## Example Usage
153
+ #
154
+ # In addition to the methods it mixes in through the Enumerable module, class
155
+ # Array has proprietary methods for accessing, searching and otherwise
156
+ # manipulating arrays.
157
+ #
158
+ # Some of the more common ones are illustrated below.
159
+ #
160
+ # ## Accessing Elements
161
+ #
162
+ # Elements in an array can be retrieved using the Array#[] method. It can take
163
+ # a single integer argument (a numeric index), a pair of arguments (start and
164
+ # length) or a range. Negative indices start counting from the end, with -1
165
+ # being the last element.
166
+ #
167
+ # arr = [1, 2, 3, 4, 5, 6]
168
+ # arr[2] #=> 3
169
+ # arr[100] #=> nil
170
+ # arr[-3] #=> 4
171
+ # arr[2, 3] #=> [3, 4, 5]
172
+ # arr[1..4] #=> [2, 3, 4, 5]
173
+ # arr[1..-3] #=> [2, 3, 4]
174
+ #
175
+ # Another way to access a particular array element is by using the #at method
176
+ #
177
+ # arr.at(0) #=> 1
178
+ #
179
+ # The #slice method works in an identical manner to Array#[].
180
+ #
181
+ # To raise an error for indices outside of the array bounds or else to provide a
182
+ # default value when that happens, you can use #fetch.
183
+ #
184
+ # arr = ['a', 'b', 'c', 'd', 'e', 'f']
185
+ # arr.fetch(100) #=> IndexError: index 100 outside of array bounds: -6...6
186
+ # arr.fetch(100, "oops") #=> "oops"
187
+ #
188
+ # The special methods #first and #last will return the first and last elements
189
+ # of an array, respectively.
190
+ #
191
+ # arr.first #=> 1
192
+ # arr.last #=> 6
193
+ #
194
+ # To return the first `n` elements of an array, use #take
195
+ #
196
+ # arr.take(3) #=> [1, 2, 3]
197
+ #
198
+ # #drop does the opposite of #take, by returning the elements after `n` elements
199
+ # have been dropped:
200
+ #
201
+ # arr.drop(3) #=> [4, 5, 6]
202
+ #
203
+ # ## Obtaining Information about an Array
204
+ #
205
+ # An array keeps track of its own length at all times. To query an array about
206
+ # the number of elements it contains, use #length, #count or #size.
207
+ #
208
+ # browsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'IE']
209
+ # browsers.length #=> 5
210
+ # browsers.count #=> 5
211
+ #
212
+ # To check whether an array contains any elements at all
213
+ #
214
+ # browsers.empty? #=> false
215
+ #
216
+ # To check whether a particular item is included in the array
217
+ #
218
+ # browsers.include?('Konqueror') #=> false
219
+ #
220
+ # ## Adding Items to an Array
221
+ #
222
+ # Items can be added to the end of an array by using either #push or #<<
223
+ #
224
+ # arr = [1, 2, 3, 4]
225
+ # arr.push(5) #=> [1, 2, 3, 4, 5]
226
+ # arr << 6 #=> [1, 2, 3, 4, 5, 6]
227
+ #
228
+ # #unshift will add a new item to the beginning of an array.
229
+ #
230
+ # arr.unshift(0) #=> [0, 1, 2, 3, 4, 5, 6]
231
+ #
232
+ # With #insert you can add a new element to an array at any position.
233
+ #
234
+ # arr.insert(3, 'apple') #=> [0, 1, 2, 'apple', 3, 4, 5, 6]
235
+ #
236
+ # Using the #insert method, you can also insert multiple values at once:
237
+ #
238
+ # arr.insert(3, 'orange', 'pear', 'grapefruit')
239
+ # #=> [0, 1, 2, "orange", "pear", "grapefruit", "apple", 3, 4, 5, 6]
240
+ #
241
+ # ## Removing Items from an Array
242
+ #
243
+ # The method #pop removes the last element in an array and returns it:
244
+ #
245
+ # arr = [1, 2, 3, 4, 5, 6]
246
+ # arr.pop #=> 6
247
+ # arr #=> [1, 2, 3, 4, 5]
248
+ #
249
+ # To retrieve and at the same time remove the first item, use #shift:
250
+ #
251
+ # arr.shift #=> 1
252
+ # arr #=> [2, 3, 4, 5]
253
+ #
254
+ # To delete an element at a particular index:
255
+ #
256
+ # arr.delete_at(2) #=> 4
257
+ # arr #=> [2, 3, 5]
258
+ #
259
+ # To delete a particular element anywhere in an array, use #delete:
260
+ #
261
+ # arr = [1, 2, 2, 3]
262
+ # arr.delete(2) #=> 2
263
+ # arr #=> [1,3]
264
+ #
265
+ # A useful method if you need to remove `nil` values from an array is #compact:
266
+ #
267
+ # arr = ['foo', 0, nil, 'bar', 7, 'baz', nil]
268
+ # arr.compact #=> ['foo', 0, 'bar', 7, 'baz']
269
+ # arr #=> ['foo', 0, nil, 'bar', 7, 'baz', nil]
270
+ # arr.compact! #=> ['foo', 0, 'bar', 7, 'baz']
271
+ # arr #=> ['foo', 0, 'bar', 7, 'baz']
272
+ #
273
+ # Another common need is to remove duplicate elements from an array.
274
+ #
275
+ # It has the non-destructive #uniq, and destructive method #uniq!
276
+ #
277
+ # arr = [2, 5, 6, 556, 6, 6, 8, 9, 0, 123, 556]
278
+ # arr.uniq #=> [2, 5, 6, 556, 8, 9, 0, 123]
279
+ #
280
+ # ## Iterating over an Array
281
+ #
282
+ # Like all classes that include the Enumerable module, class Array has an each
283
+ # method, which defines what elements should be iterated over and how. In case
284
+ # of Array#each, all elements in `self` are yielded to the supplied block in
285
+ # sequence.
286
+ #
287
+ # Note that this operation leaves the array unchanged.
288
+ #
289
+ # arr = [1, 2, 3, 4, 5]
290
+ # arr.each {|a| print a -= 10, " "}
291
+ # # prints: -9 -8 -7 -6 -5
292
+ # #=> [1, 2, 3, 4, 5]
293
+ #
294
+ # Another sometimes useful iterator is #reverse_each which will iterate over the
295
+ # elements in the array in reverse order.
296
+ #
297
+ # words = %w[first second third fourth fifth sixth]
298
+ # str = ""
299
+ # words.reverse_each {|word| str += "#{word} "}
300
+ # p str #=> "sixth fifth fourth third second first "
301
+ #
302
+ # The #map method can be used to create a new array based on the original array,
303
+ # but with the values modified by the supplied block:
304
+ #
305
+ # arr.map {|a| 2*a} #=> [2, 4, 6, 8, 10]
306
+ # arr #=> [1, 2, 3, 4, 5]
307
+ # arr.map! {|a| a**2} #=> [1, 4, 9, 16, 25]
308
+ # arr #=> [1, 4, 9, 16, 25]
309
+ #
310
+ # ## Selecting Items from an Array
311
+ #
312
+ # Elements can be selected from an array according to criteria defined in a
313
+ # block. The selection can happen in a destructive or a non-destructive manner.
314
+ # While the destructive operations will modify the array they were called on,
315
+ # the non-destructive methods usually return a new array with the selected
316
+ # elements, but leave the original array unchanged.
317
+ #
318
+ # ### Non-destructive Selection
319
+ #
320
+ # arr = [1, 2, 3, 4, 5, 6]
321
+ # arr.select {|a| a > 3} #=> [4, 5, 6]
322
+ # arr.reject {|a| a < 3} #=> [3, 4, 5, 6]
323
+ # arr.drop_while {|a| a < 4} #=> [4, 5, 6]
324
+ # arr #=> [1, 2, 3, 4, 5, 6]
325
+ #
326
+ # ### Destructive Selection
327
+ #
328
+ # #select! and #reject! are the corresponding destructive methods to #select and
329
+ # #reject
330
+ #
331
+ # Similar to #select vs. #reject, #delete_if and #keep_if have the exact
332
+ # opposite result when supplied with the same block:
333
+ #
334
+ # arr.delete_if {|a| a < 4} #=> [4, 5, 6]
335
+ # arr #=> [4, 5, 6]
336
+ #
337
+ # arr = [1, 2, 3, 4, 5, 6]
338
+ # arr.keep_if {|a| a < 4} #=> [1, 2, 3]
339
+ # arr #=> [1, 2, 3]
340
+ #
341
+ # ## What's Here
342
+ #
343
+ # First, what's elsewhere. Class Array:
344
+ #
345
+ # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
346
+ # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
347
+ # provides dozens of additional methods.
348
+ #
349
+ # Here, class Array provides methods that are useful for:
350
+ #
351
+ # * [Creating an Array](rdoc-ref:Array@Methods+for+Creating+an+Array)
352
+ # * [Querying](rdoc-ref:Array@Methods+for+Querying)
353
+ # * [Comparing](rdoc-ref:Array@Methods+for+Comparing)
354
+ # * [Fetching](rdoc-ref:Array@Methods+for+Fetching)
355
+ # * [Assigning](rdoc-ref:Array@Methods+for+Assigning)
356
+ # * [Deleting](rdoc-ref:Array@Methods+for+Deleting)
357
+ # * [Combining](rdoc-ref:Array@Methods+for+Combining)
358
+ # * [Iterating](rdoc-ref:Array@Methods+for+Iterating)
359
+ # * [Converting](rdoc-ref:Array@Methods+for+Converting)
360
+ # * [And more....](rdoc-ref:Array@Other+Methods)
361
+ #
362
+ # ### Methods for Creating an Array
363
+ #
364
+ # * ::[]: Returns a new array populated with given objects.
365
+ # * ::new: Returns a new array.
366
+ # * ::try_convert: Returns a new array created from a given object.
367
+ #
368
+ # See also [Creating Arrays](rdoc-ref:Array@Creating+Arrays).
369
+ #
370
+ # ### Methods for Querying
371
+ #
372
+ # * #all?: Returns whether all elements meet a given criterion.
373
+ # * #any?: Returns whether any element meets a given criterion.
374
+ # * #count: Returns the count of elements that meet a given criterion.
375
+ # * #empty?: Returns whether there are no elements.
376
+ # * #find_index (aliased as #index): Returns the index of the first element
377
+ # that meets a given criterion.
378
+ # * #hash: Returns the integer hash code.
379
+ # * #include?: Returns whether any element <code>==</code> a given object.
380
+ # * #length (aliased as #size): Returns the count of elements.
381
+ # * #none?: Returns whether no element <code>==</code> a given object.
382
+ # * #one?: Returns whether exactly one element <code>==</code> a given object.
383
+ # * #rindex: Returns the index of the last element that meets a given
384
+ # criterion.
385
+ #
386
+ # ### Methods for Comparing
387
+ #
388
+ # * #<=>: Returns -1, 0, or 1, as `self` is less than, equal to, or greater
389
+ # than a given object.
390
+ # * #==: Returns whether each element in `self` is <code>==</code> to the
391
+ # corresponding element in a given object.
392
+ # * #eql?: Returns whether each element in `self` is <code>eql?</code> to the
393
+ # corresponding element in a given object.
394
+ #
395
+ # ### Methods for Fetching
396
+ #
397
+ # These methods do not modify `self`.
398
+ #
399
+ # * #[] (aliased as #slice): Returns consecutive elements as determined by a
400
+ # given argument.
401
+ # * #assoc: Returns the first element that is an array whose first element
402
+ # <code>==</code> a given object.
403
+ # * #at: Returns the element at a given offset.
404
+ # * #bsearch: Returns an element selected via a binary search as determined by
405
+ # a given block.
406
+ # * #bsearch_index: Returns the index of an element selected via a binary
407
+ # search as determined by a given block.
408
+ # * #compact: Returns an array containing all non-`nil` elements.
409
+ # * #dig: Returns the object in nested objects that is specified by a given
410
+ # index and additional arguments.
411
+ # * #drop: Returns trailing elements as determined by a given index.
412
+ # * #drop_while: Returns trailing elements as determined by a given block.
413
+ # * #fetch: Returns the element at a given offset.
414
+ # * #fetch_values: Returns elements at given offsets.
415
+ # * #first: Returns one or more leading elements.
416
+ # * #last: Returns one or more trailing elements.
417
+ # * #max: Returns one or more maximum-valued elements, as determined by
418
+ # <code>#<=></code> or a given block.
419
+ # * #min: Returns one or more minimum-valued elements, as determined by
420
+ # <code>#<=></code> or a given block.
421
+ # * #minmax: Returns the minimum-valued and maximum-valued elements, as
422
+ # determined by <code>#<=></code> or a given block.
423
+ # * #rassoc: Returns the first element that is an array whose second element
424
+ # <code>==</code> a given object.
425
+ # * #reject: Returns an array containing elements not rejected by a given
426
+ # block.
427
+ # * #reverse: Returns all elements in reverse order.
428
+ # * #rotate: Returns all elements with some rotated from one end to the other.
429
+ # * #sample: Returns one or more random elements.
430
+ # * #select (aliased as #filter): Returns an array containing elements
431
+ # selected by a given block.
432
+ # * #shuffle: Returns elements in a random order.
433
+ # * #sort: Returns all elements in an order determined by <code>#<=></code> or
434
+ # a given block.
435
+ # * #take: Returns leading elements as determined by a given index.
436
+ # * #take_while: Returns leading elements as determined by a given block.
437
+ # * #uniq: Returns an array containing non-duplicate elements.
438
+ # * #values_at: Returns the elements at given offsets.
439
+ #
440
+ # ### Methods for Assigning
441
+ #
442
+ # These methods add, replace, or reorder elements in `self`.
443
+ #
444
+ # * #<<: Appends an element.
445
+ # * #[]=: Assigns specified elements with a given object.
446
+ # * #concat: Appends all elements from given arrays.
447
+ # * #fill: Replaces specified elements with specified objects.
448
+ # * #flatten!: Replaces each nested array in `self` with the elements from
449
+ # that array.
450
+ # * #initialize_copy (aliased as #replace): Replaces the content of `self`
451
+ # with the content of a given array.
452
+ # * #insert: Inserts given objects at a given offset; does not replace
453
+ # elements.
454
+ # * #push (aliased as #append): Appends elements.
455
+ # * #reverse!: Replaces `self` with its elements reversed.
456
+ # * #rotate!: Replaces `self` with its elements rotated.
457
+ # * #shuffle!: Replaces `self` with its elements in random order.
458
+ # * #sort!: Replaces `self` with its elements sorted, as determined by
459
+ # <code>#<=></code> or a given block.
460
+ # * #sort_by!: Replaces `self` with its elements sorted, as determined by a
461
+ # given block.
462
+ # * #unshift (aliased as #prepend): Prepends leading elements.
463
+ #
464
+ # ### Methods for Deleting
465
+ #
466
+ # Each of these methods removes elements from `self`:
467
+ #
468
+ # * #clear: Removes all elements.
469
+ # * #compact!: Removes all `nil` elements.
470
+ # * #delete: Removes elements equal to a given object.
471
+ # * #delete_at: Removes the element at a given offset.
472
+ # * #delete_if: Removes elements specified by a given block.
473
+ # * #keep_if: Removes elements not specified by a given block.
474
+ # * #pop: Removes and returns the last element.
475
+ # * #reject!: Removes elements specified by a given block.
476
+ # * #select! (aliased as #filter!): Removes elements not specified by a given
477
+ # block.
478
+ # * #shift: Removes and returns the first element.
479
+ # * #slice!: Removes and returns a sequence of elements.
480
+ # * #uniq!: Removes duplicates.
481
+ #
482
+ # ### Methods for Combining
483
+ #
484
+ # * #&: Returns an array containing elements found both in `self` and a given
485
+ # array.
486
+ # * #+: Returns an array containing all elements of `self` followed by all
487
+ # elements of a given array.
488
+ # * #-: Returns an array containing all elements of `self` that are not found
489
+ # in a given array.
490
+ # * #|: Returns an array containing all element of `self` and all elements of
491
+ # a given array, duplicates removed.
492
+ # * #difference: Returns an array containing all elements of `self` that are
493
+ # not found in any of the given arrays..
494
+ # * #intersection: Returns an array containing elements found both in `self`
495
+ # and in each given array.
496
+ # * #product: Returns or yields all combinations of elements from `self` and
497
+ # given arrays.
498
+ # * #reverse: Returns an array containing all elements of `self` in reverse
499
+ # order.
500
+ # * #union: Returns an array containing all elements of `self` and all
501
+ # elements of given arrays, duplicates removed.
502
+ #
503
+ # ### Methods for Iterating
504
+ #
505
+ # * #combination: Calls a given block with combinations of elements of `self`;
506
+ # a combination does not use the same element more than once.
507
+ # * #cycle: Calls a given block with each element, then does so again, for a
508
+ # specified number of times, or forever.
509
+ # * #each: Passes each element to a given block.
510
+ # * #each_index: Passes each element index to a given block.
511
+ # * #permutation: Calls a given block with permutations of elements of `self`;
512
+ # a permutation does not use the same element more than once.
513
+ # * #repeated_combination: Calls a given block with combinations of elements
514
+ # of `self`; a combination may use the same element more than once.
515
+ # * #repeated_permutation: Calls a given block with permutations of elements
516
+ # of `self`; a permutation may use the same element more than once.
517
+ # * #reverse_each: Passes each element, in reverse order, to a given block.
518
+ #
519
+ # ### Methods for Converting
520
+ #
521
+ # * #collect (aliased as #map): Returns an array containing the block
522
+ # return-value for each element.
523
+ # * #collect! (aliased as #map!): Replaces each element with a block
524
+ # return-value.
525
+ # * #flatten: Returns an array that is a recursive flattening of `self`.
526
+ # * #inspect (aliased as #to_s): Returns a new String containing the elements.
527
+ # * #join: Returns a new String containing the elements joined by the field
528
+ # separator.
529
+ # * #to_a: Returns `self` or a new array containing all elements.
530
+ # * #to_ary: Returns `self`.
531
+ # * #to_h: Returns a new hash formed from the elements.
532
+ # * #transpose: Transposes `self`, which must be an array of arrays.
533
+ # * #zip: Returns a new array of arrays containing `self` and given arrays.
534
+ #
535
+ # ### Other Methods
536
+ #
537
+ # * #*: Returns one of the following:
538
+ #
539
+ # * With integer argument `n`, a new array that is the concatenation of
540
+ # `n` copies of `self`.
541
+ # * With string argument `field_separator`, a new string that is
542
+ # equivalent to <code>join(field_separator)</code>.
543
+ #
544
+ # * #pack: Packs the elements into a binary sequence.
545
+ # * #sum: Returns a sum of elements according to either <code>+</code> or a
546
+ # given block.
547
+ #
548
+ %a{annotate:rdoc:source:from=array.c}
549
+ class Array[unchecked out E]
550
+ include Enumerable[E]
551
+
552
+ # Interface for random number generations; used with `Array#shuffle`, `Array#shuffle!`, and `Array#sample`.
553
+ interface _Rand
554
+ # Generate a random number up to, but excluding, `max`
555
+ def rand: (Integer max) -> int
556
+ end
557
+
558
+ # <!--
559
+ # rdoc-file=array.c
560
+ # - Array.new -> new_empty_array
561
+ # - Array.new(array) -> new_array
562
+ # - Array.new(size, default_value = nil) -> new_array
563
+ # - Array.new(size = 0) {|index| ... } -> new_array
564
+ # -->
565
+ # Returns a new array.
566
+ #
567
+ # With no block and no argument given, returns a new empty array:
568
+ #
569
+ # Array.new # => []
570
+ #
571
+ # With no block and array argument given, returns a new array with the same
572
+ # elements:
573
+ #
574
+ # Array.new([:foo, 'bar', 2]) # => [:foo, "bar", 2]
575
+ #
576
+ # With no block and integer argument given, returns a new array containing that
577
+ # many instances of the given `default_value`:
578
+ #
579
+ # Array.new(0) # => []
580
+ # Array.new(3) # => [nil, nil, nil]
581
+ # Array.new(2, 3) # => [3, 3]
582
+ #
583
+ # With a block given, returns an array of the given `size`; calls the block with
584
+ # each `index` in the range <code>(0...size)</code>; the element at that `index`
585
+ # in the returned array is the blocks return value:
586
+ #
587
+ # Array.new(3) {|index| "Element #{index}" } # => ["Element 0", "Element 1", "Element 2"]
588
+ #
589
+ # A common pitfall for new Rubyists is providing an expression as
590
+ # `default_value`:
591
+ #
592
+ # array = Array.new(2, {})
593
+ # array # => [{}, {}]
594
+ # array[0][:a] = 1
595
+ # array # => [{a: 1}, {a: 1}], as array[0] and array[1] are same object
596
+ #
597
+ # If you want the elements of the array to be distinct, you should pass a block:
598
+ #
599
+ # array = Array.new(2) { {} }
600
+ # array # => [{}, {}]
601
+ # array[0][:a] = 1
602
+ # array # => [{a: 1}, {}], as array[0] and array[1] are different objects
603
+ #
604
+ # Raises TypeError if the first argument is not either an array or an
605
+ # [integer-convertible
606
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects)).
607
+ # Raises ArgumentError if the first argument is a negative integer.
608
+ #
609
+ # Related: see [Methods for Creating an
610
+ # Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
611
+ #
612
+ def initialize: () -> void
613
+ | (array[E] array) -> void
614
+ | (int size, ?E default_value) -> void
615
+ | (int size) { (Integer index) -> E } -> void
616
+
617
+ # <!--
618
+ # rdoc-file=array.c
619
+ # - [](*args)
620
+ # -->
621
+ # Returns a new array, populated with the given objects:
622
+ #
623
+ # Array[1, 'a', /^A/] # => [1, "a", /^A/]
624
+ # Array[] # => []
625
+ # Array.[](1, 'a', /^A/) # => [1, "a", /^A/]
626
+ #
627
+ # Related: see [Methods for Creating an
628
+ # Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
629
+ #
630
+ def self.[]: [U] (*U) -> Array[U] # this technically returns a subclass, but `instance(self)` isn't a thing
631
+
632
+ # <!--
633
+ # rdoc-file=array.c
634
+ # - Array.try_convert(object) -> object, new_array, or nil
635
+ # -->
636
+ # Attempts to return an array, based on the given `object`.
637
+ #
638
+ # If `object` is an array, returns `object`.
639
+ #
640
+ # Otherwise if `object` responds to <code>:to_ary</code>. calls
641
+ # <code>object.to_ary</code>: if the return value is an array or `nil`, returns
642
+ # that value; if not, raises TypeError.
643
+ #
644
+ # Otherwise returns `nil`.
645
+ #
646
+ # Related: see [Methods for Creating an
647
+ # Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
648
+ #
649
+ def self.try_convert: [A < Array[U], U] (A array) -> A
650
+ | [U] (array[U] ary) -> Array[U]?
651
+ | (untyped) -> Array[untyped]?
652
+
653
+ # <!--
654
+ # rdoc-file=array.c
655
+ # - self & other_array -> new_array
656
+ # -->
657
+ # Returns a new array containing the *intersection* of `self` and `other_array`;
658
+ # that is, containing those elements found in both `self` and `other_array`:
659
+ #
660
+ # [0, 1, 2, 3] & [1, 2] # => [1, 2]
661
+ #
662
+ # Omits duplicates:
663
+ #
664
+ # [0, 1, 1, 0] & [0, 1] # => [0, 1]
665
+ #
666
+ # Preserves order from `self`:
667
+ #
668
+ # [0, 1, 2] & [3, 2, 1, 0] # => [0, 1, 2]
669
+ #
670
+ # Identifies common elements using method <code>#eql?</code> (as defined in each
671
+ # element of `self`).
672
+ #
673
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
674
+ #
675
+ def &: (array[untyped] other_array) -> Array[E] # where E: _Eql?[T]
676
+
677
+ # <!--
678
+ # rdoc-file=array.c
679
+ # - self * n -> new_array
680
+ # - self * string_separator -> new_string
681
+ # -->
682
+ # When non-negative integer argument `n` is given, returns a new array built by
683
+ # concatenating `n` copies of `self`:
684
+ #
685
+ # a = ['x', 'y']
686
+ # a * 3 # => ["x", "y", "x", "y", "x", "y"]
687
+ #
688
+ # When string argument `string_separator` is given, equivalent to
689
+ # <code>self.join(string_separator)</code>:
690
+ #
691
+ # [0, [0, 1], {foo: 0}] * ', ' # => "0, 0, 1, {foo: 0}"
692
+ #
693
+ def *: (string string_separator) -> String # where E: _ToS
694
+ | (int n) -> Array[E] # where E: _ToS
695
+
696
+ # <!--
697
+ # rdoc-file=array.c
698
+ # - self + other_array -> new_array
699
+ # -->
700
+ # Returns a new array containing all elements of `self` followed by all elements
701
+ # of `other_array`:
702
+ #
703
+ # a = [0, 1] + [2, 3]
704
+ # a # => [0, 1, 2, 3]
705
+ #
706
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
707
+ #
708
+ def +: [U] (array[U] other_array) -> Array[E | U]
709
+
710
+ # <!--
711
+ # rdoc-file=array.c
712
+ # - self - other_array -> new_array
713
+ # -->
714
+ # Returns a new array containing only those elements of `self` that are not
715
+ # found in `other_array`; the order from `self` is preserved:
716
+ #
717
+ # [0, 1, 1, 2, 1, 1, 3, 1, 1] - [1] # => [0, 2, 3]
718
+ # [0, 1, 1, 2, 1, 1, 3, 1, 1] - [3, 2, 0, :foo] # => [1, 1, 1, 1, 1, 1]
719
+ # [0, 1, 2] - [:foo] # => [0, 1, 2]
720
+ #
721
+ # Element are compared using method <code>#eql?</code> (as defined in each
722
+ # element of `self`).
723
+ #
724
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
725
+ #
726
+ def -: (array[untyped] other_array) -> Array[E] # where E: _Eql?[T]
727
+
728
+ # <!--
729
+ # rdoc-file=array.c
730
+ # - self << object -> self
731
+ # -->
732
+ # Appends `object` as the last element in `self`; returns `self`:
733
+ #
734
+ # [:foo, 'bar', 2] << :baz # => [:foo, "bar", 2, :baz]
735
+ #
736
+ # Appends `object` as a single element, even if it is another array:
737
+ #
738
+ # [:foo, 'bar', 2] << [3, 4] # => [:foo, "bar", 2, [3, 4]]
739
+ #
740
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
741
+ #
742
+ def <<: (E object) -> self
743
+
744
+ # <!--
745
+ # rdoc-file=array.c
746
+ # - self <=> other_array -> -1, 0, or 1
747
+ # -->
748
+ # Returns -1, 0, or 1 as `self` is determined to be less than, equal to, or
749
+ # greater than `other_array`.
750
+ #
751
+ # Iterates over each index `i` in <code>(0...self.size)</code>:
752
+ #
753
+ # * Computes <code>result[i]</code> as <code>self[i] <=>
754
+ # other_array[i]</code>.
755
+ # * Immediately returns 1 if <code>result[i]</code> is 1:
756
+ #
757
+ # [0, 1, 2] <=> [0, 0, 2] # => 1
758
+ #
759
+ # * Immediately returns -1 if <code>result[i]</code> is -1:
760
+ #
761
+ # [0, 1, 2] <=> [0, 2, 2] # => -1
762
+ #
763
+ # * Continues if <code>result[i]</code> is 0.
764
+ #
765
+ # When every `result` is 0, returns <code>self.size <=> other_array.size</code>
766
+ # (see Integer#<=>):
767
+ #
768
+ # [0, 1, 2] <=> [0, 1] # => 1
769
+ # [0, 1, 2] <=> [0, 1, 2] # => 0
770
+ # [0, 1, 2] <=> [0, 1, 2, 3] # => -1
771
+ #
772
+ # Note that when `other_array` is larger than `self`, its trailing elements do
773
+ # not affect the result:
774
+ #
775
+ # [0, 1, 2] <=> [0, 1, 2, -3] # => -1
776
+ # [0, 1, 2] <=> [0, 1, 2, 0] # => -1
777
+ # [0, 1, 2] <=> [0, 1, 2, 3] # => -1
778
+ #
779
+ # Related: see [Methods for Comparing](rdoc-ref:Array@Methods+for+Comparing).
780
+ #
781
+ def <=>: (untyped) -> Integer? # Until we can do `where E: RBS::Ops::_Compare`, this is always going to return `Integer?`
782
+
783
+ # <!--
784
+ # rdoc-file=array.c
785
+ # - self == other_array -> true or false
786
+ # -->
787
+ # Returns whether both:
788
+ #
789
+ # * `self` and `other_array` are the same size.
790
+ # * Their corresponding elements are the same; that is, for each index `i` in
791
+ # <code>(0...self.size)</code>, <code>self[i] == other_array[i]</code>.
792
+ #
793
+ # Examples:
794
+ #
795
+ # [:foo, 'bar', 2] == [:foo, 'bar', 2] # => true
796
+ # [:foo, 'bar', 2] == [:foo, 'bar', 2.0] # => true
797
+ # [:foo, 'bar', 2] == [:foo, 'bar'] # => false # Different sizes.
798
+ # [:foo, 'bar', 2] == [:foo, 'bar', 3] # => false # Different elements.
799
+ #
800
+ # This method is different from method Array#eql?, which compares elements using
801
+ # <code>Object#eql?</code>.
802
+ #
803
+ # Related: see [Methods for Comparing](rdoc-ref:Array@Methods+for+Comparing).
804
+ #
805
+ def ==: (untyped other) -> bool
806
+
807
+ # <!--
808
+ # rdoc-file=array.c
809
+ # - self[index] -> object or nil
810
+ # - self[start, length] -> object or nil
811
+ # - self[range] -> object or nil
812
+ # - self[aseq] -> object or nil
813
+ # - slice(index) -> object or nil
814
+ # - slice(start, length) -> object or nil
815
+ # - slice(range) -> object or nil
816
+ # - slice(aseq) -> object or nil
817
+ # -->
818
+ # Returns elements from `self`; does not modify `self`.
819
+ #
820
+ # In brief:
821
+ #
822
+ # a = [:foo, 'bar', 2]
823
+ #
824
+ # # Single argument index: returns one element.
825
+ # a[0] # => :foo # Zero-based index.
826
+ # a[-1] # => 2 # Negative index counts backwards from end.
827
+ #
828
+ # # Arguments start and length: returns an array.
829
+ # a[1, 2] # => ["bar", 2]
830
+ # a[-2, 2] # => ["bar", 2] # Negative start counts backwards from end.
831
+ #
832
+ # # Single argument range: returns an array.
833
+ # a[0..1] # => [:foo, "bar"]
834
+ # a[0..-2] # => [:foo, "bar"] # Negative range-begin counts backwards from end.
835
+ # a[-2..2] # => ["bar", 2] # Negative range-end counts backwards from end.
836
+ #
837
+ # When a single integer argument `index` is given, returns the element at offset
838
+ # `index`:
839
+ #
840
+ # a = [:foo, 'bar', 2]
841
+ # a[0] # => :foo
842
+ # a[2] # => 2
843
+ # a # => [:foo, "bar", 2]
844
+ #
845
+ # If `index` is negative, counts backwards from the end of `self`:
846
+ #
847
+ # a = [:foo, 'bar', 2]
848
+ # a[-1] # => 2
849
+ # a[-2] # => "bar"
850
+ #
851
+ # If `index` is out of range, returns `nil`.
852
+ #
853
+ # When two Integer arguments `start` and `length` are given, returns a new array
854
+ # of size `length` containing successive elements beginning at offset `start`:
855
+ #
856
+ # a = [:foo, 'bar', 2]
857
+ # a[0, 2] # => [:foo, "bar"]
858
+ # a[1, 2] # => ["bar", 2]
859
+ #
860
+ # If <code>start + length</code> is greater than <code>self.length</code>,
861
+ # returns all elements from offset `start` to the end:
862
+ #
863
+ # a = [:foo, 'bar', 2]
864
+ # a[0, 4] # => [:foo, "bar", 2]
865
+ # a[1, 3] # => ["bar", 2]
866
+ # a[2, 2] # => [2]
867
+ #
868
+ # If <code>start == self.size</code> and <code>length >= 0</code>, returns a new
869
+ # empty array.
870
+ #
871
+ # If `length` is negative, returns `nil`.
872
+ #
873
+ # When a single Range argument `range` is given, treats <code>range.min</code>
874
+ # as `start` above and <code>range.size</code> as `length` above:
875
+ #
876
+ # a = [:foo, 'bar', 2]
877
+ # a[0..1] # => [:foo, "bar"]
878
+ # a[1..2] # => ["bar", 2]
879
+ #
880
+ # Special case: If <code>range.start == a.size</code>, returns a new empty
881
+ # array.
882
+ #
883
+ # If <code>range.end</code> is negative, calculates the end index from the end:
884
+ #
885
+ # a = [:foo, 'bar', 2]
886
+ # a[0..-1] # => [:foo, "bar", 2]
887
+ # a[0..-2] # => [:foo, "bar"]
888
+ # a[0..-3] # => [:foo]
889
+ #
890
+ # If <code>range.start</code> is negative, calculates the start index from the
891
+ # end:
892
+ #
893
+ # a = [:foo, 'bar', 2]
894
+ # a[-1..2] # => [2]
895
+ # a[-2..2] # => ["bar", 2]
896
+ # a[-3..2] # => [:foo, "bar", 2]
897
+ #
898
+ # If <code>range.start</code> is larger than the array size, returns `nil`.
899
+ #
900
+ # a = [:foo, 'bar', 2]
901
+ # a[4..1] # => nil
902
+ # a[4..0] # => nil
903
+ # a[4..-1] # => nil
904
+ #
905
+ # When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
906
+ # an array of elements corresponding to the indexes produced by the sequence.
907
+ #
908
+ # a = ['--', 'data1', '--', 'data2', '--', 'data3']
909
+ # a[(1..).step(2)] # => ["data1", "data2", "data3"]
910
+ #
911
+ # Unlike slicing with range, if the start or the end of the arithmetic sequence
912
+ # is larger than array size, throws RangeError.
913
+ #
914
+ # a = ['--', 'data1', '--', 'data2', '--', 'data3']
915
+ # a[(1..11).step(2)]
916
+ # # RangeError (((1..11).step(2)) out of range)
917
+ # a[(7..).step(2)]
918
+ # # RangeError (((7..).step(2)) out of range)
919
+ #
920
+ # If given a single argument, and its type is not one of the listed, tries to
921
+ # convert it to Integer, and raises if it is impossible:
922
+ #
923
+ # a = [:foo, 'bar', 2]
924
+ # # Raises TypeError (no implicit conversion of Symbol into Integer):
925
+ # a[:foo]
926
+ #
927
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
928
+ #
929
+ def []: %a{implicitly-returns-nil} (int index) -> E
930
+ | (int start, int length) -> Array[E]?
931
+ | (range[int] range) -> Array[E]?
932
+
933
+ # <!--
934
+ # rdoc-file=array.c
935
+ # - self[index] = object -> object
936
+ # - self[start, length] = object -> object
937
+ # - self[range] = object -> object
938
+ # -->
939
+ # Assigns elements in `self`, based on the given `object`; returns `object`.
940
+ #
941
+ # In brief:
942
+ #
943
+ # a_orig = [:foo, 'bar', 2]
944
+ #
945
+ # # With argument index.
946
+ # a = a_orig.dup
947
+ # a[0] = 'foo' # => "foo"
948
+ # a # => ["foo", "bar", 2]
949
+ # a = a_orig.dup
950
+ # a[7] = 'foo' # => "foo"
951
+ # a # => [:foo, "bar", 2, nil, nil, nil, nil, "foo"]
952
+ #
953
+ # # With arguments start and length.
954
+ # a = a_orig.dup
955
+ # a[0, 2] = 'foo' # => "foo"
956
+ # a # => ["foo", 2]
957
+ # a = a_orig.dup
958
+ # a[6, 50] = 'foo' # => "foo"
959
+ # a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
960
+ #
961
+ # # With argument range.
962
+ # a = a_orig.dup
963
+ # a[0..1] = 'foo' # => "foo"
964
+ # a # => ["foo", 2]
965
+ # a = a_orig.dup
966
+ # a[6..50] = 'foo' # => "foo"
967
+ # a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
968
+ #
969
+ # When Integer argument `index` is given, assigns `object` to an element in
970
+ # `self`.
971
+ #
972
+ # If `index` is non-negative, assigns `object` the element at offset `index`:
973
+ #
974
+ # a = [:foo, 'bar', 2]
975
+ # a[0] = 'foo' # => "foo"
976
+ # a # => ["foo", "bar", 2]
977
+ #
978
+ # If `index` is greater than <code>self.length</code>, extends the array:
979
+ #
980
+ # a = [:foo, 'bar', 2]
981
+ # a[7] = 'foo' # => "foo"
982
+ # a # => [:foo, "bar", 2, nil, nil, nil, nil, "foo"]
983
+ #
984
+ # If `index` is negative, counts backwards from the end of the array:
985
+ #
986
+ # a = [:foo, 'bar', 2]
987
+ # a[-1] = 'two' # => "two"
988
+ # a # => [:foo, "bar", "two"]
989
+ #
990
+ # When Integer arguments `start` and `length` are given and `object` is not an
991
+ # array, removes <code>length - 1</code> elements beginning at offset `start`,
992
+ # and assigns `object` at offset `start`:
993
+ #
994
+ # a = [:foo, 'bar', 2]
995
+ # a[0, 2] = 'foo' # => "foo"
996
+ # a # => ["foo", 2]
997
+ #
998
+ # If `start` is negative, counts backwards from the end of the array:
999
+ #
1000
+ # a = [:foo, 'bar', 2]
1001
+ # a[-2, 2] = 'foo' # => "foo"
1002
+ # a # => [:foo, "foo"]
1003
+ #
1004
+ # If `start` is non-negative and outside the array (<code> >= self.size</code>),
1005
+ # extends the array with `nil`, assigns `object` at offset `start`, and ignores
1006
+ # `length`:
1007
+ #
1008
+ # a = [:foo, 'bar', 2]
1009
+ # a[6, 50] = 'foo' # => "foo"
1010
+ # a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
1011
+ #
1012
+ # If `length` is zero, shifts elements at and following offset `start` and
1013
+ # assigns `object` at offset `start`:
1014
+ #
1015
+ # a = [:foo, 'bar', 2]
1016
+ # a[1, 0] = 'foo' # => "foo"
1017
+ # a # => [:foo, "foo", "bar", 2]
1018
+ #
1019
+ # If `length` is too large for the existing array, does not extend the array:
1020
+ #
1021
+ # a = [:foo, 'bar', 2]
1022
+ # a[1, 5] = 'foo' # => "foo"
1023
+ # a # => [:foo, "foo"]
1024
+ #
1025
+ # When Range argument `range` is given and `object` is not an array, removes
1026
+ # <code>length - 1</code> elements beginning at offset `start`, and assigns
1027
+ # `object` at offset `start`:
1028
+ #
1029
+ # a = [:foo, 'bar', 2]
1030
+ # a[0..1] = 'foo' # => "foo"
1031
+ # a # => ["foo", 2]
1032
+ #
1033
+ # if <code>range.begin</code> is negative, counts backwards from the end of the
1034
+ # array:
1035
+ #
1036
+ # a = [:foo, 'bar', 2]
1037
+ # a[-2..2] = 'foo' # => "foo"
1038
+ # a # => [:foo, "foo"]
1039
+ #
1040
+ # If the array length is less than <code>range.begin</code>, extends the array
1041
+ # with `nil`, assigns `object` at offset <code>range.begin</code>, and ignores
1042
+ # `length`:
1043
+ #
1044
+ # a = [:foo, 'bar', 2]
1045
+ # a[6..50] = 'foo' # => "foo"
1046
+ # a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
1047
+ #
1048
+ # If <code>range.end</code> is zero, shifts elements at and following offset
1049
+ # `start` and assigns `object` at offset `start`:
1050
+ #
1051
+ # a = [:foo, 'bar', 2]
1052
+ # a[1..0] = 'foo' # => "foo"
1053
+ # a # => [:foo, "foo", "bar", 2]
1054
+ #
1055
+ # If <code>range.end</code> is negative, assigns `object` at offset `start`,
1056
+ # retains <code>range.end.abs -1</code> elements past that, and removes those
1057
+ # beyond:
1058
+ #
1059
+ # a = [:foo, 'bar', 2]
1060
+ # a[1..-1] = 'foo' # => "foo"
1061
+ # a # => [:foo, "foo"]
1062
+ # a = [:foo, 'bar', 2]
1063
+ # a[1..-2] = 'foo' # => "foo"
1064
+ # a # => [:foo, "foo", 2]
1065
+ # a = [:foo, 'bar', 2]
1066
+ # a[1..-3] = 'foo' # => "foo"
1067
+ # a # => [:foo, "foo", "bar", 2]
1068
+ # a = [:foo, 'bar', 2]
1069
+ #
1070
+ # If <code>range.end</code> is too large for the existing array, replaces array
1071
+ # elements, but does not extend the array with `nil` values:
1072
+ #
1073
+ # a = [:foo, 'bar', 2]
1074
+ # a[1..5] = 'foo' # => "foo"
1075
+ # a # => [:foo, "foo"]
1076
+ #
1077
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
1078
+ #
1079
+ def []=: (int index, E object) -> E
1080
+ | [T < _ToAry[E]] (range[int?] range, T array) -> T
1081
+ | (range[int?] range, E object) -> E
1082
+ | [T < _ToAry[E]] (int start, int length, T array) -> T
1083
+ | (int start, int length, E object) -> E
1084
+
1085
+ # <!--
1086
+ # rdoc-file=array.c
1087
+ # - all? -> true or false
1088
+ # - all?(object) -> true or false
1089
+ # - all? {|element| ... } -> true or false
1090
+ # -->
1091
+ # Returns whether for every element of `self`, a given criterion is satisfied.
1092
+ #
1093
+ # With no block and no argument, returns whether every element of `self` is
1094
+ # truthy:
1095
+ #
1096
+ # [[], {}, '', 0, 0.0, Object.new].all? # => true # All truthy objects.
1097
+ # [[], {}, '', 0, 0.0, nil].all? # => false # nil is not truthy.
1098
+ # [[], {}, '', 0, 0.0, false].all? # => false # false is not truthy.
1099
+ #
1100
+ # With argument `object` given, returns whether <code>object === ele</code> for
1101
+ # every element `ele` in `self`:
1102
+ #
1103
+ # [0, 0, 0].all?(0) # => true
1104
+ # [0, 1, 2].all?(1) # => false
1105
+ # ['food', 'fool', 'foot'].all?(/foo/) # => true
1106
+ # ['food', 'drink'].all?(/foo/) # => false
1107
+ #
1108
+ # With a block given, calls the block with each element in `self`; returns
1109
+ # whether the block returns only truthy values:
1110
+ #
1111
+ # [0, 1, 2].all? { |ele| ele < 3 } # => true
1112
+ # [0, 1, 2].all? { |ele| ele < 2 } # => false
1113
+ #
1114
+ # With both a block and argument `object` given, ignores the block and uses
1115
+ # `object` as above.
1116
+ #
1117
+ # **Special case**: returns `true` if `self` is empty (regardless of any given
1118
+ # argument or block).
1119
+ #
1120
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
1121
+ #
1122
+ def all?: () -> bool
1123
+ | (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
1124
+ | () { (E element) -> boolish } -> bool
1125
+
1126
+ # <!--
1127
+ # rdoc-file=array.c
1128
+ # - any? -> true or false
1129
+ # - any?(object) -> true or false
1130
+ # - any? {|element| ... } -> true or false
1131
+ # -->
1132
+ # Returns whether for any element of `self`, a given criterion is satisfied.
1133
+ #
1134
+ # With no block and no argument, returns whether any element of `self` is
1135
+ # truthy:
1136
+ #
1137
+ # [nil, false, []].any? # => true # Array object is truthy.
1138
+ # [nil, false, {}].any? # => true # Hash object is truthy.
1139
+ # [nil, false, ''].any? # => true # String object is truthy.
1140
+ # [nil, false].any? # => false # Nil and false are not truthy.
1141
+ #
1142
+ # With argument `object` given, returns whether <code>object === ele</code> for
1143
+ # any element `ele` in `self`:
1144
+ #
1145
+ # [nil, false, 0].any?(0) # => true
1146
+ # [nil, false, 1].any?(0) # => false
1147
+ # [nil, false, 'food'].any?(/foo/) # => true
1148
+ # [nil, false, 'food'].any?(/bar/) # => false
1149
+ #
1150
+ # With a block given, calls the block with each element in `self`; returns
1151
+ # whether the block returns any truthy value:
1152
+ #
1153
+ # [0, 1, 2].any? {|ele| ele < 1 } # => true
1154
+ # [0, 1, 2].any? {|ele| ele < 0 } # => false
1155
+ #
1156
+ # With both a block and argument `object` given, ignores the block and uses
1157
+ # `object` as above.
1158
+ #
1159
+ # **Special case**: returns `false` if `self` is empty (regardless of any given
1160
+ # argument or block).
1161
+ #
1162
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
1163
+ #
1164
+ def any?: () -> bool
1165
+ | (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
1166
+ | () { (E element) -> boolish } -> bool
1167
+
1168
+ # <!-- rdoc-file=array.c -->
1169
+ # Appends each argument in `objects` to `self`; returns `self`:
1170
+ #
1171
+ # a = [:foo, 'bar', 2] # => [:foo, "bar", 2]
1172
+ # a.push(:baz, :bat) # => [:foo, "bar", 2, :baz, :bat]
1173
+ #
1174
+ # Appends each argument as a single element, even if it is another array:
1175
+ #
1176
+ # a = [:foo, 'bar', 2] # => [:foo, "bar", 2]
1177
+ # a.push([:baz, :bat], [:bam, :bad]) # => [:foo, "bar", 2, [:baz, :bat], [:bam, :bad]]
1178
+ #
1179
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
1180
+ #
1181
+ alias append push
1182
+
1183
+ # <!--
1184
+ # rdoc-file=array.c
1185
+ # - assoc(object) -> found_array or nil
1186
+ # -->
1187
+ # Returns the first element `ele` in `self` such that `ele` is an array and
1188
+ # <code>ele[0] == object</code>:
1189
+ #
1190
+ # a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
1191
+ # a.assoc(4) # => [4, 5, 6]
1192
+ #
1193
+ # Returns `nil` if no such element is found.
1194
+ #
1195
+ # Related: Array#rassoc; see also [Methods for
1196
+ # Fetching](rdoc-ref:Array@Methods+for+Fetching).
1197
+ #
1198
+ def assoc: (untyped object) -> Array[untyped]? # where E: _ToAry[X], object: _Equal
1199
+
1200
+ # <!--
1201
+ # rdoc-file=array.c
1202
+ # - at(index) -> object or nil
1203
+ # -->
1204
+ # Returns the element of `self` specified by the given `index` or `nil` if there
1205
+ # is no such element; `index` must be an [integer-convertible
1206
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
1207
+ #
1208
+ # For non-negative `index`, returns the element of `self` at offset `index`:
1209
+ #
1210
+ # a = [:foo, 'bar', 2]
1211
+ # a.at(0) # => :foo
1212
+ # a.at(2) # => 2
1213
+ # a.at(2.0) # => 2
1214
+ #
1215
+ # For negative `index`, counts backwards from the end of `self`:
1216
+ #
1217
+ # a.at(-2) # => "bar"
1218
+ #
1219
+ # Related: Array#[]; see also [Methods for
1220
+ # Fetching](rdoc-ref:Array@Methods+for+Fetching).
1221
+ #
1222
+ def at: %a{implicitly-returns-nil} (int index) -> E
1223
+
1224
+ # <!--
1225
+ # rdoc-file=array.c
1226
+ # - bsearch {|element| ... } -> found_element or nil
1227
+ # - bsearch -> new_enumerator
1228
+ # -->
1229
+ # Returns the element from `self` found by a binary search, or `nil` if the
1230
+ # search found no suitable element.
1231
+ #
1232
+ # See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
1233
+ #
1234
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1235
+ #
1236
+ def bsearch: () { (E element) -> bool? } -> E?
1237
+ | () { (E element) -> Numeric? } -> E?
1238
+ | () -> Enumerator[E, E?]
1239
+
1240
+ # <!--
1241
+ # rdoc-file=array.c
1242
+ # - bsearch_index {|element| ... } -> integer or nil
1243
+ # - bsearch_index -> new_enumerator
1244
+ # -->
1245
+ # Returns the integer index of the element from `self` found by a binary search,
1246
+ # or `nil` if the search found no suitable element.
1247
+ #
1248
+ # See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
1249
+ #
1250
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1251
+ #
1252
+ def bsearch_index: () { (E element) -> bool? } -> Integer?
1253
+ | () { (E element) -> Numeric? } -> Integer?
1254
+ | () -> Enumerator[E, Integer?]
1255
+
1256
+ # <!--
1257
+ # rdoc-file=array.c
1258
+ # - clear -> self
1259
+ # -->
1260
+ # Removes all elements from `self`; returns `self`:
1261
+ #
1262
+ # a = [:foo, 'bar', 2]
1263
+ # a.clear # => []
1264
+ #
1265
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
1266
+ #
1267
+ def clear: () -> self
1268
+
1269
+ # <!--
1270
+ # rdoc-file=array.c
1271
+ # - collect {|element| ... } -> new_array
1272
+ # - collect -> new_enumerator
1273
+ # - map {|element| ... } -> new_array
1274
+ # - map -> new_enumerator
1275
+ # -->
1276
+ # With a block given, calls the block with each element of `self`; returns a new
1277
+ # array whose elements are the return values from the block:
1278
+ #
1279
+ # a = [:foo, 'bar', 2]
1280
+ # a1 = a.map {|element| element.class }
1281
+ # a1 # => [Symbol, String, Integer]
1282
+ #
1283
+ # With no block given, returns a new Enumerator.
1284
+ #
1285
+ # Related: #collect!; see also [Methods for
1286
+ # Converting](rdoc-ref:Array@Methods+for+Converting).
1287
+ #
1288
+ def collect: [T] () { (E item) -> T } -> Array[T]
1289
+ | () -> Enumerator[E, Array[untyped]]
1290
+
1291
+ # <!--
1292
+ # rdoc-file=array.c
1293
+ # - collect! {|element| ... } -> self
1294
+ # - collect! -> new_enumerator
1295
+ # - map! {|element| ... } -> self
1296
+ # - map! -> new_enumerator
1297
+ # -->
1298
+ # With a block given, calls the block with each element of `self` and replaces
1299
+ # the element with the block's return value; returns `self`:
1300
+ #
1301
+ # a = [:foo, 'bar', 2]
1302
+ # a.map! { |element| element.class } # => [Symbol, String, Integer]
1303
+ #
1304
+ # With no block given, returns a new Enumerator.
1305
+ #
1306
+ # Related: #collect; see also [Methods for
1307
+ # Converting](rdoc-ref:Array@Methods+for+Converting).
1308
+ #
1309
+ def collect!: () { (E element) -> E } -> self
1310
+ | () -> Enumerator[E, self]
1311
+
1312
+ # <!--
1313
+ # rdoc-file=array.c
1314
+ # - combination(count) {|element| ... } -> self
1315
+ # - combination(count) -> new_enumerator
1316
+ # -->
1317
+ # When a block and a positive [integer-convertible
1318
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects)
1319
+ # argument `count` (<code>0 < count <= self.size</code>) are given, calls the
1320
+ # block with each combination of `self` of size `count`; returns `self`:
1321
+ #
1322
+ # a = %w[a b c] # => ["a", "b", "c"]
1323
+ # a.combination(2) {|combination| p combination } # => ["a", "b", "c"]
1324
+ #
1325
+ # Output:
1326
+ #
1327
+ # ["a", "b"]
1328
+ # ["a", "c"]
1329
+ # ["b", "c"]
1330
+ #
1331
+ # The order of the yielded combinations is not guaranteed.
1332
+ #
1333
+ # When `count` is zero, calls the block once with a new empty array:
1334
+ #
1335
+ # a.combination(0) {|combination| p combination }
1336
+ # [].combination(0) {|combination| p combination }
1337
+ #
1338
+ # Output:
1339
+ #
1340
+ # []
1341
+ # []
1342
+ #
1343
+ # When `count` is negative or larger than <code>self.size</code> and `self` is
1344
+ # non-empty, does not call the block:
1345
+ #
1346
+ # a.combination(-1) {|combination| fail 'Cannot happen' } # => ["a", "b", "c"]
1347
+ # a.combination(4) {|combination| fail 'Cannot happen' } # => ["a", "b", "c"]
1348
+ #
1349
+ # With no block given, returns a new Enumerator.
1350
+ #
1351
+ # Related: Array#permutation; see also [Methods for
1352
+ # Iterating](rdoc-ref:Array@Methods+for+Iterating).
1353
+ #
1354
+ def combination: (int count) { (Array[E] combination) -> void } -> self
1355
+ | (int count) -> Enumerator[Array[E], self]
1356
+
1357
+ # <!--
1358
+ # rdoc-file=array.c
1359
+ # - compact -> new_array
1360
+ # -->
1361
+ # Returns a new array containing only the non-`nil` elements from `self`;
1362
+ # element order is preserved:
1363
+ #
1364
+ # a = [nil, 0, nil, false, nil, '', nil, [], nil, {}]
1365
+ # a.compact # => [0, false, "", [], {}]
1366
+ #
1367
+ # Related: Array#compact!; see also [Methods for
1368
+ # Deleting](rdoc-ref:Array@Methods+for+Deleting).
1369
+ #
1370
+ def compact: () -> Array[E] # it'd be nice if there was a way to do `Array[E - nil]`
1371
+
1372
+ # <!--
1373
+ # rdoc-file=array.c
1374
+ # - compact! -> self or nil
1375
+ # -->
1376
+ # Removes all `nil` elements from `self`; Returns `self` if any elements are
1377
+ # removed, `nil` otherwise:
1378
+ #
1379
+ # a = [nil, 0, nil, false, nil, '', nil, [], nil, {}]
1380
+ # a.compact! # => [0, false, "", [], {}]
1381
+ # a # => [0, false, "", [], {}]
1382
+ # a.compact! # => nil
1383
+ #
1384
+ # Related: Array#compact; see also [Methods for
1385
+ # Deleting](rdoc-ref:Array@Methods+for+Deleting).
1386
+ #
1387
+ def compact!: () -> self?
1388
+
1389
+ # <!--
1390
+ # rdoc-file=array.c
1391
+ # - concat(*other_arrays) -> self
1392
+ # -->
1393
+ # Adds to `self` all elements from each array in `other_arrays`; returns `self`:
1394
+ #
1395
+ # a = [0, 1]
1396
+ # a.concat(['two', 'three'], [:four, :five], a)
1397
+ # # => [0, 1, "two", "three", :four, :five, 0, 1]
1398
+ #
1399
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
1400
+ #
1401
+ def concat: (*array[E] other_arrays) -> self
1402
+
1403
+ # <!--
1404
+ # rdoc-file=array.c
1405
+ # - count -> integer
1406
+ # - count(object) -> integer
1407
+ # - count {|element| ... } -> integer
1408
+ # -->
1409
+ # Returns a count of specified elements.
1410
+ #
1411
+ # With no argument and no block, returns the count of all elements:
1412
+ #
1413
+ # [0, :one, 'two', 3, 3.0].count # => 5
1414
+ #
1415
+ # With argument `object` given, returns the count of elements <code>==</code> to
1416
+ # `object`:
1417
+ #
1418
+ # [0, :one, 'two', 3, 3.0].count(3) # => 2
1419
+ #
1420
+ # With no argument and a block given, calls the block with each element; returns
1421
+ # the count of elements for which the block returns a truthy value:
1422
+ #
1423
+ # [0, 1, 2, 3].count {|element| element > 1 } # => 2
1424
+ #
1425
+ # With argument `object` and a block given, issues a warning, ignores the block,
1426
+ # and returns the count of elements <code>==</code> to `object`.
1427
+ #
1428
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
1429
+ #
1430
+ def count: () ?{ (E element) -> boolish } -> Integer
1431
+ | (untyped object) -> Integer # where E: RBS::Ops::_Equal
1432
+
1433
+ # <!--
1434
+ # rdoc-file=array.c
1435
+ # - cycle(count = nil) {|element| ... } -> nil
1436
+ # - cycle(count = nil) -> new_enumerator
1437
+ # -->
1438
+ # With a block given, may call the block, depending on the value of argument
1439
+ # `count`; `count` must be an [integer-convertible
1440
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects), or
1441
+ # `nil`.
1442
+ #
1443
+ # When `count` is positive, calls the block with each element, then does so
1444
+ # repeatedly, until it has done so `count` times; returns `nil`:
1445
+ #
1446
+ # output = []
1447
+ # [0, 1].cycle(2) {|element| output.push(element) } # => nil
1448
+ # output # => [0, 1, 0, 1]
1449
+ #
1450
+ # When `count` is zero or negative, does not call the block:
1451
+ #
1452
+ # [0, 1].cycle(0) {|element| fail 'Cannot happen' } # => nil
1453
+ # [0, 1].cycle(-1) {|element| fail 'Cannot happen' } # => nil
1454
+ #
1455
+ # When `count` is `nil`, cycles forever:
1456
+ #
1457
+ # # Prints 0 and 1 forever.
1458
+ # [0, 1].cycle {|element| puts element }
1459
+ # [0, 1].cycle(nil) {|element| puts element }
1460
+ #
1461
+ # With no block given, returns a new Enumerator.
1462
+ #
1463
+ # Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
1464
+ #
1465
+ def cycle: (?int? n) { (E element) -> void } -> nil
1466
+ | (?int? n) -> Enumerator[E, nil]
1467
+
1468
+ # <!--
1469
+ # rdoc-file=array.c
1470
+ # - deconstruct()
1471
+ # -->
1472
+ #
1473
+ def deconstruct: () -> self
1474
+
1475
+ # <!--
1476
+ # rdoc-file=array.c
1477
+ # - delete(object) -> last_removed_object
1478
+ # - delete(object) {|element| ... } -> last_removed_object or block_return
1479
+ # -->
1480
+ # Removes zero or more elements from `self`.
1481
+ #
1482
+ # With no block given, removes from `self` each element `ele` such that
1483
+ # <code>ele == object</code>; returns the last removed element:
1484
+ #
1485
+ # a = [0, 1, 2, 2.0]
1486
+ # a.delete(2) # => 2.0
1487
+ # a # => [0, 1]
1488
+ #
1489
+ # Returns `nil` if no elements removed:
1490
+ #
1491
+ # a.delete(2) # => nil
1492
+ #
1493
+ # With a block given, removes from `self` each element `ele` such that <code>ele
1494
+ # == object</code>.
1495
+ #
1496
+ # If any such elements are found, ignores the block and returns the last removed
1497
+ # element:
1498
+ #
1499
+ # a = [0, 1, 2, 2.0]
1500
+ # a.delete(2) {|element| fail 'Cannot happen' } # => 2.0
1501
+ # a # => [0, 1]
1502
+ #
1503
+ # If no such element is found, returns the block's return value:
1504
+ #
1505
+ # a.delete(2) {|element| "Element #{element} not found." }
1506
+ # # => "Element 2 not found."
1507
+ #
1508
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
1509
+ #
1510
+ def delete: (untyped object) -> E? # where E: _Comparable
1511
+ | [S, T] (S object) { (S object) -> T } -> (E | T)
1512
+
1513
+ # <!--
1514
+ # rdoc-file=array.c
1515
+ # - delete_at(index) -> removed_object or nil
1516
+ # -->
1517
+ # Removes the element of `self` at the given `index`, which must be an
1518
+ # [integer-convertible
1519
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
1520
+ #
1521
+ # When `index` is non-negative, deletes the element at offset `index`:
1522
+ #
1523
+ # a = [:foo, 'bar', 2]
1524
+ # a.delete_at(1) # => "bar"
1525
+ # a # => [:foo, 2]
1526
+ #
1527
+ # When `index` is negative, counts backward from the end of the array:
1528
+ #
1529
+ # a = [:foo, 'bar', 2]
1530
+ # a.delete_at(-2) # => "bar"
1531
+ # a # => [:foo, 2]
1532
+ #
1533
+ # When `index` is out of range, returns `nil`.
1534
+ #
1535
+ # a = [:foo, 'bar', 2]
1536
+ # a.delete_at(3) # => nil
1537
+ # a.delete_at(-4) # => nil
1538
+ #
1539
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
1540
+ #
1541
+ def delete_at: %a{implicitly-returns-nil} (int index) -> E
1542
+
1543
+ # <!--
1544
+ # rdoc-file=array.c
1545
+ # - delete_if {|element| ... } -> self
1546
+ # - delete_if -> new_numerator
1547
+ # -->
1548
+ # With a block given, calls the block with each element of `self`; removes the
1549
+ # element if the block returns a truthy value; returns `self`:
1550
+ #
1551
+ # a = [:foo, 'bar', 2, 'bat']
1552
+ # a.delete_if {|element| element.to_s.start_with?('b') } # => [:foo, 2]
1553
+ #
1554
+ # With no block given, returns a new Enumerator.
1555
+ #
1556
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
1557
+ #
1558
+ def delete_if: () { (E item) -> boolish } -> self
1559
+ | () -> Enumerator[E, self]
1560
+
1561
+ # <!-- rdoc-file=array.c -->
1562
+ # Returns the first element for which the block returns a truthy value.
1563
+ #
1564
+ # With a block given, calls the block with successive elements of the array;
1565
+ # returns the first element for which the block returns a truthy value:
1566
+ #
1567
+ # [1, 3, 5].find {|element| element > 2} # => 3
1568
+ #
1569
+ # If no such element is found, calls `if_none_proc` and returns its return
1570
+ # value.
1571
+ #
1572
+ # [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1
1573
+ #
1574
+ # With no block given, returns an Enumerator.
1575
+ #
1576
+ alias detect find
1577
+
1578
+ # <!--
1579
+ # rdoc-file=array.c
1580
+ # - difference(*other_arrays = []) -> new_array
1581
+ # -->
1582
+ # Returns a new array containing only those elements from `self` that are not
1583
+ # found in any of the given `other_arrays`; items are compared using
1584
+ # <code>eql?</code>; order from `self` is preserved:
1585
+ #
1586
+ # [0, 1, 1, 2, 1, 1, 3, 1, 1].difference([1]) # => [0, 2, 3]
1587
+ # [0, 1, 2, 3].difference([3, 0], [1, 3]) # => [2]
1588
+ # [0, 1, 2].difference([4]) # => [0, 1, 2]
1589
+ # [0, 1, 2].difference # => [0, 1, 2]
1590
+ #
1591
+ # Returns a copy of `self` if no arguments are given.
1592
+ #
1593
+ # Related: Array#-; see also [Methods for
1594
+ # Combining](rdoc-ref:Array@Methods+for+Combining).
1595
+ #
1596
+ def difference: (*array[untyped] other_arrays) -> Array[E]
1597
+
1598
+ # <!--
1599
+ # rdoc-file=array.c
1600
+ # - dig(index, *identifiers) -> object
1601
+ # -->
1602
+ # Finds and returns the object in nested object specified by `index` and
1603
+ # `identifiers`; the nested objects may be instances of various classes. See
1604
+ # [Dig Methods](rdoc-ref:dig_methods.rdoc).
1605
+ #
1606
+ # Examples:
1607
+ #
1608
+ # a = [:foo, [:bar, :baz, [:bat, :bam]]]
1609
+ # a.dig(1) # => [:bar, :baz, [:bat, :bam]]
1610
+ # a.dig(1, 2) # => [:bat, :bam]
1611
+ # a.dig(1, 2, 0) # => :bat
1612
+ # a.dig(1, 2, 3) # => nil
1613
+ #
1614
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1615
+ #
1616
+ def dig: (int index) -> E?
1617
+ | (int index, untyped, *untyped) -> untyped
1618
+
1619
+ # <!--
1620
+ # rdoc-file=array.c
1621
+ # - drop(count) -> new_array
1622
+ # -->
1623
+ # Returns a new array containing all but the first `count` element of `self`,
1624
+ # where `count` is a non-negative integer; does not modify `self`.
1625
+ #
1626
+ # Examples:
1627
+ #
1628
+ # a = [0, 1, 2, 3, 4, 5]
1629
+ # a.drop(0) # => [0, 1, 2, 3, 4, 5]
1630
+ # a.drop(1) # => [1, 2, 3, 4, 5]
1631
+ # a.drop(2) # => [2, 3, 4, 5]
1632
+ # a.drop(9) # => []
1633
+ #
1634
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1635
+ #
1636
+ def drop: (int count) -> Array[E]
1637
+
1638
+ # <!--
1639
+ # rdoc-file=array.c
1640
+ # - drop_while {|element| ... } -> new_array
1641
+ # - drop_while -> new_enumerator
1642
+ # -->
1643
+ # With a block given, calls the block with each successive element of `self`;
1644
+ # stops if the block returns `false` or `nil`; returns a new array *omitting*
1645
+ # those elements for which the block returned a truthy value; does not modify
1646
+ # `self`:
1647
+ #
1648
+ # a = [0, 1, 2, 3, 4, 5]
1649
+ # a.drop_while {|element| element < 3 } # => [3, 4, 5]
1650
+ #
1651
+ # With no block given, returns a new Enumerator.
1652
+ #
1653
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1654
+ #
1655
+ def drop_while: () { (E element) -> boolish } -> Array[E]
1656
+ | () -> Enumerator[E, Array[E]]
1657
+
1658
+ # <!--
1659
+ # rdoc-file=array.c
1660
+ # - each {|element| ... } -> self
1661
+ # - each -> new_enumerator
1662
+ # -->
1663
+ # With a block given, iterates over the elements of `self`, passing each element
1664
+ # to the block; returns `self`:
1665
+ #
1666
+ # a = [:foo, 'bar', 2]
1667
+ # a.each {|element| puts "#{element.class} #{element}" }
1668
+ #
1669
+ # Output:
1670
+ #
1671
+ # Symbol foo
1672
+ # String bar
1673
+ # Integer 2
1674
+ #
1675
+ # Allows the array to be modified during iteration:
1676
+ #
1677
+ # a = [:foo, 'bar', 2]
1678
+ # a.each {|element| puts element; a.clear if element.to_s.start_with?('b') }
1679
+ #
1680
+ # Output:
1681
+ #
1682
+ # foo
1683
+ # bar
1684
+ #
1685
+ # With no block given, returns a new Enumerator.
1686
+ #
1687
+ # Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
1688
+ #
1689
+ def each: () { (E element) -> void } -> self
1690
+ | () -> Enumerator[E, self]
1691
+
1692
+ # <!--
1693
+ # rdoc-file=array.c
1694
+ # - each_index {|index| ... } -> self
1695
+ # - each_index -> new_enumerator
1696
+ # -->
1697
+ # With a block given, iterates over the elements of `self`, passing each *array
1698
+ # index* to the block; returns `self`:
1699
+ #
1700
+ # a = [:foo, 'bar', 2]
1701
+ # a.each_index {|index| puts "#{index} #{a[index]}" }
1702
+ #
1703
+ # Output:
1704
+ #
1705
+ # 0 foo
1706
+ # 1 bar
1707
+ # 2 2
1708
+ #
1709
+ # Allows the array to be modified during iteration:
1710
+ #
1711
+ # a = [:foo, 'bar', 2]
1712
+ # a.each_index {|index| puts index; a.clear if index > 0 }
1713
+ # a # => []
1714
+ #
1715
+ # Output:
1716
+ #
1717
+ # 0
1718
+ # 1
1719
+ #
1720
+ # With no block given, returns a new Enumerator.
1721
+ #
1722
+ # Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
1723
+ #
1724
+ def each_index: () { (Integer index) -> void } -> self
1725
+ | () -> Enumerator[Integer, self]
1726
+
1727
+ # <!--
1728
+ # rdoc-file=array.c
1729
+ # - empty? -> true or false
1730
+ # -->
1731
+ # Returns `true` if the count of elements in `self` is zero, `false` otherwise.
1732
+ #
1733
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
1734
+ #
1735
+ def empty?: () -> bool
1736
+
1737
+ # <!--
1738
+ # rdoc-file=array.c
1739
+ # - eql?(other_array) -> true or false
1740
+ # -->
1741
+ # Returns `true` if `self` and `other_array` are the same size, and if, for each
1742
+ # index `i` in `self`, <code>self[i].eql?(other_array[i])</code>:
1743
+ #
1744
+ # a0 = [:foo, 'bar', 2]
1745
+ # a1 = [:foo, 'bar', 2]
1746
+ # a1.eql?(a0) # => true
1747
+ #
1748
+ # Otherwise, returns `false`.
1749
+ #
1750
+ # This method is different from method Array#==, which compares using method
1751
+ # <code>Object#==</code>.
1752
+ #
1753
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
1754
+ #
1755
+ def eql?: (untyped other) -> bool
1756
+
1757
+ # <!--
1758
+ # rdoc-file=array.c
1759
+ # - fetch(index) -> element
1760
+ # - fetch(index, default_value) -> element or default_value
1761
+ # - fetch(index) {|index| ... } -> element or block_return_value
1762
+ # -->
1763
+ # Returns the element of `self` at offset `index` if `index` is in range;
1764
+ # `index` must be an [integer-convertible
1765
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
1766
+ #
1767
+ # With the single argument `index` and no block, returns the element at offset
1768
+ # `index`:
1769
+ #
1770
+ # a = [:foo, 'bar', 2]
1771
+ # a.fetch(1) # => "bar"
1772
+ # a.fetch(1.1) # => "bar"
1773
+ #
1774
+ # If `index` is negative, counts from the end of the array:
1775
+ #
1776
+ # a = [:foo, 'bar', 2]
1777
+ # a.fetch(-1) # => 2
1778
+ # a.fetch(-2) # => "bar"
1779
+ #
1780
+ # With arguments `index` and `default_value` (which may be any object) and no
1781
+ # block, returns `default_value` if `index` is out-of-range:
1782
+ #
1783
+ # a = [:foo, 'bar', 2]
1784
+ # a.fetch(1, nil) # => "bar"
1785
+ # a.fetch(3, :foo) # => :foo
1786
+ #
1787
+ # With argument `index` and a block, returns the element at offset `index` if
1788
+ # index is in range (and the block is not called); otherwise calls the block
1789
+ # with index and returns its return value:
1790
+ #
1791
+ # a = [:foo, 'bar', 2]
1792
+ # a.fetch(1) {|index| raise 'Cannot happen' } # => "bar"
1793
+ # a.fetch(50) {|index| "Value for #{index}" } # => "Value for 50"
1794
+ #
1795
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1796
+ #
1797
+ def fetch: (int index) -> E
1798
+ | [T] (int index, T default) -> (E | T)
1799
+ | [I < _ToInt, T] (I index) { (I index) -> T } -> (E | T)
1800
+
1801
+ # <!--
1802
+ # rdoc-file=array.rb
1803
+ # - fetch_values(*indexes) -> new_array
1804
+ # - fetch_values(*indexes) { |index| ... } -> new_array
1805
+ # -->
1806
+ # With no block given, returns a new array containing the elements of `self` at
1807
+ # the offsets specified by `indexes`. Each of the `indexes` must be an
1808
+ # [integer-convertible
1809
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects):
1810
+ #
1811
+ # a = [:foo, :bar, :baz]
1812
+ # a.fetch_values(2, 0) # => [:baz, :foo]
1813
+ # a.fetch_values(2.1, 0) # => [:baz, :foo]
1814
+ # a.fetch_values # => []
1815
+ #
1816
+ # For a negative index, counts backwards from the end of the array:
1817
+ #
1818
+ # a.fetch_values(-2, -1) # [:bar, :baz]
1819
+ #
1820
+ # When no block is given, raises an exception if any index is out of range.
1821
+ #
1822
+ # With a block given, for each index:
1823
+ #
1824
+ # * If the index is in range, uses an element of `self` (as above).
1825
+ # * Otherwise, calls the block with the index and uses the block's return
1826
+ # value.
1827
+ #
1828
+ # Example:
1829
+ #
1830
+ # a = [:foo, :bar, :baz]
1831
+ # a.fetch_values(1, 0, 42, 777) { |index| index.to_s }
1832
+ # # => [:bar, :foo, "42", "777"]
1833
+ #
1834
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
1835
+ #
1836
+ def fetch_values: (*int indexes) -> Array[E]
1837
+ | [I < _ToInt, T] (*I indexes) { (I index) -> T } -> Array[E | T]
1838
+
1839
+ # <!--
1840
+ # rdoc-file=array.c
1841
+ # - fill(object, start = nil, count = nil) -> self
1842
+ # - fill(object, range) -> self
1843
+ # - fill(start = nil, count = nil) {|element| ... } -> self
1844
+ # - fill(range) {|element| ... } -> self
1845
+ # -->
1846
+ # Replaces selected elements in `self`; may add elements to `self`; always
1847
+ # returns `self` (never a new array).
1848
+ #
1849
+ # In brief:
1850
+ #
1851
+ # # Non-negative start.
1852
+ # ['a', 'b', 'c', 'd'].fill('-', 1, 2) # => ["a", "-", "-", "d"]
1853
+ # ['a', 'b', 'c', 'd'].fill(1, 2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1854
+ #
1855
+ # # Extends with specified values if necessary.
1856
+ # ['a', 'b', 'c', 'd'].fill('-', 3, 2) # => ["a", "b", "c", "-", "-"]
1857
+ # ['a', 'b', 'c', 'd'].fill(3, 2) {|e| e.to_s } # => ["a", "b", "c", "3", "4"]
1858
+ #
1859
+ # # Fills with nils if necessary.
1860
+ # ['a', 'b', 'c', 'd'].fill('-', 6, 2) # => ["a", "b", "c", "d", nil, nil, "-", "-"]
1861
+ # ['a', 'b', 'c', 'd'].fill(6, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, nil, "6", "7"]
1862
+ #
1863
+ # # For negative start, counts backwards from the end.
1864
+ # ['a', 'b', 'c', 'd'].fill('-', -3, 3) # => ["a", "-", "-", "-"]
1865
+ # ['a', 'b', 'c', 'd'].fill(-3, 3) {|e| e.to_s } # => ["a", "1", "2", "3"]
1866
+ #
1867
+ # # Range.
1868
+ # ['a', 'b', 'c', 'd'].fill('-', 1..2) # => ["a", "-", "-", "d"]
1869
+ # ['a', 'b', 'c', 'd'].fill(1..2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1870
+ #
1871
+ # When arguments `start` and `count` are given, they select the elements of
1872
+ # `self` to be replaced; each must be an [integer-convertible
1873
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects) (or
1874
+ # `nil`):
1875
+ #
1876
+ # * `start` specifies the zero-based offset of the first element to be
1877
+ # replaced; `nil` means zero.
1878
+ # * `count` is the number of consecutive elements to be replaced; `nil` means
1879
+ # "all the rest."
1880
+ #
1881
+ # With argument `object` given, that one object is used for all replacements:
1882
+ #
1883
+ # o = Object.new # => #<Object:0x0000014e7bff7600>
1884
+ # a = ['a', 'b', 'c', 'd'] # => ["a", "b", "c", "d"]
1885
+ # a.fill(o, 1, 2)
1886
+ # # => ["a", #<Object:0x0000014e7bff7600>, #<Object:0x0000014e7bff7600>, "d"]
1887
+ #
1888
+ # With a block given, the block is called once for each element to be replaced;
1889
+ # the value passed to the block is the *index* of the element to be replaced
1890
+ # (not the element itself); the block's return value replaces the element:
1891
+ #
1892
+ # a = ['a', 'b', 'c', 'd'] # => ["a", "b", "c", "d"]
1893
+ # a.fill(1, 2) {|element| element.to_s } # => ["a", "1", "2", "d"]
1894
+ #
1895
+ # For arguments `start` and `count`:
1896
+ #
1897
+ # * If `start` is non-negative, replaces `count` elements beginning at offset
1898
+ # `start`:
1899
+ #
1900
+ # ['a', 'b', 'c', 'd'].fill('-', 0, 2) # => ["-", "-", "c", "d"]
1901
+ # ['a', 'b', 'c', 'd'].fill('-', 1, 2) # => ["a", "-", "-", "d"]
1902
+ # ['a', 'b', 'c', 'd'].fill('-', 2, 2) # => ["a", "b", "-", "-"]
1903
+ #
1904
+ # ['a', 'b', 'c', 'd'].fill(0, 2) {|e| e.to_s } # => ["0", "1", "c", "d"]
1905
+ # ['a', 'b', 'c', 'd'].fill(1, 2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1906
+ # ['a', 'b', 'c', 'd'].fill(2, 2) {|e| e.to_s } # => ["a", "b", "2", "3"]
1907
+ #
1908
+ # Extends `self` if necessary:
1909
+ #
1910
+ # ['a', 'b', 'c', 'd'].fill('-', 3, 2) # => ["a", "b", "c", "-", "-"]
1911
+ # ['a', 'b', 'c', 'd'].fill('-', 4, 2) # => ["a", "b", "c", "d", "-", "-"]
1912
+ #
1913
+ # ['a', 'b', 'c', 'd'].fill(3, 2) {|e| e.to_s } # => ["a", "b", "c", "3", "4"]
1914
+ # ['a', 'b', 'c', 'd'].fill(4, 2) {|e| e.to_s } # => ["a", "b", "c", "d", "4", "5"]
1915
+ #
1916
+ # Fills with `nil` if necessary:
1917
+ #
1918
+ # ['a', 'b', 'c', 'd'].fill('-', 5, 2) # => ["a", "b", "c", "d", nil, "-", "-"]
1919
+ # ['a', 'b', 'c', 'd'].fill('-', 6, 2) # => ["a", "b", "c", "d", nil, nil, "-", "-"]
1920
+ #
1921
+ # ['a', 'b', 'c', 'd'].fill(5, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, "5", "6"]
1922
+ # ['a', 'b', 'c', 'd'].fill(6, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, nil, "6", "7"]
1923
+ #
1924
+ # Does nothing if `count` is non-positive:
1925
+ #
1926
+ # ['a', 'b', 'c', 'd'].fill('-', 2, 0) # => ["a", "b", "c", "d"]
1927
+ # ['a', 'b', 'c', 'd'].fill('-', 2, -100) # => ["a", "b", "c", "d"]
1928
+ # ['a', 'b', 'c', 'd'].fill('-', 6, -100) # => ["a", "b", "c", "d"]
1929
+ #
1930
+ # ['a', 'b', 'c', 'd'].fill(2, 0) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1931
+ # ['a', 'b', 'c', 'd'].fill(2, -100) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1932
+ # ['a', 'b', 'c', 'd'].fill(6, -100) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1933
+ #
1934
+ # * If `start` is negative, counts backwards from the end of `self`:
1935
+ #
1936
+ # ['a', 'b', 'c', 'd'].fill('-', -4, 3) # => ["-", "-", "-", "d"]
1937
+ # ['a', 'b', 'c', 'd'].fill('-', -3, 3) # => ["a", "-", "-", "-"]
1938
+ #
1939
+ # ['a', 'b', 'c', 'd'].fill(-4, 3) {|e| e.to_s } # => ["0", "1", "2", "d"]
1940
+ # ['a', 'b', 'c', 'd'].fill(-3, 3) {|e| e.to_s } # => ["a", "1", "2", "3"]
1941
+ #
1942
+ # Extends `self` if necessary:
1943
+ #
1944
+ # ['a', 'b', 'c', 'd'].fill('-', -2, 3) # => ["a", "b", "-", "-", "-"]
1945
+ # ['a', 'b', 'c', 'd'].fill('-', -1, 3) # => ["a", "b", "c", "-", "-", "-"]
1946
+ #
1947
+ # ['a', 'b', 'c', 'd'].fill(-2, 3) {|e| e.to_s } # => ["a", "b", "2", "3", "4"]
1948
+ # ['a', 'b', 'c', 'd'].fill(-1, 3) {|e| e.to_s } # => ["a", "b", "c", "3", "4", "5"]
1949
+ #
1950
+ # Starts at the beginning of `self` if `start` is negative and out-of-range:
1951
+ #
1952
+ # ['a', 'b', 'c', 'd'].fill('-', -5, 2) # => ["-", "-", "c", "d"]
1953
+ # ['a', 'b', 'c', 'd'].fill('-', -6, 2) # => ["-", "-", "c", "d"]
1954
+ #
1955
+ # ['a', 'b', 'c', 'd'].fill(-5, 2) {|e| e.to_s } # => ["0", "1", "c", "d"]
1956
+ # ['a', 'b', 'c', 'd'].fill(-6, 2) {|e| e.to_s } # => ["0", "1", "c", "d"]
1957
+ #
1958
+ # Does nothing if `count` is non-positive:
1959
+ #
1960
+ # ['a', 'b', 'c', 'd'].fill('-', -2, 0) # => ["a", "b", "c", "d"]
1961
+ # ['a', 'b', 'c', 'd'].fill('-', -2, -1) # => ["a", "b", "c", "d"]
1962
+ #
1963
+ # ['a', 'b', 'c', 'd'].fill(-2, 0) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1964
+ # ['a', 'b', 'c', 'd'].fill(-2, -1) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
1965
+ #
1966
+ # When argument `range` is given, it must be a Range object whose members are
1967
+ # numeric; its `begin` and `end` values determine the elements of `self` to be
1968
+ # replaced:
1969
+ #
1970
+ # * If both `begin` and `end` are positive, they specify the first and last
1971
+ # elements to be replaced:
1972
+ #
1973
+ # ['a', 'b', 'c', 'd'].fill('-', 1..2) # => ["a", "-", "-", "d"]
1974
+ # ['a', 'b', 'c', 'd'].fill(1..2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1975
+ #
1976
+ # If `end` is smaller than `begin`, replaces no elements:
1977
+ #
1978
+ # ['a', 'b', 'c', 'd'].fill('-', 2..1) # => ["a", "b", "c", "d"]
1979
+ # ['a', 'b', 'c', 'd'].fill(2..1) {|e| e.to_s } # => ["a", "b", "c", "d"]
1980
+ #
1981
+ # * If either is negative (or both are negative), counts backwards from the
1982
+ # end of `self`:
1983
+ #
1984
+ # ['a', 'b', 'c', 'd'].fill('-', -3..2) # => ["a", "-", "-", "d"]
1985
+ # ['a', 'b', 'c', 'd'].fill('-', 1..-2) # => ["a", "-", "-", "d"]
1986
+ # ['a', 'b', 'c', 'd'].fill('-', -3..-2) # => ["a", "-", "-", "d"]
1987
+ #
1988
+ # ['a', 'b', 'c', 'd'].fill(-3..2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1989
+ # ['a', 'b', 'c', 'd'].fill(1..-2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1990
+ # ['a', 'b', 'c', 'd'].fill(-3..-2) {|e| e.to_s } # => ["a", "1", "2", "d"]
1991
+ #
1992
+ # * If the `end` value is excluded (see Range#exclude_end?), omits the last
1993
+ # replacement:
1994
+ #
1995
+ # ['a', 'b', 'c', 'd'].fill('-', 1...2) # => ["a", "-", "c", "d"]
1996
+ # ['a', 'b', 'c', 'd'].fill('-', 1...-2) # => ["a", "-", "c", "d"]
1997
+ #
1998
+ # ['a', 'b', 'c', 'd'].fill(1...2) {|e| e.to_s } # => ["a", "1", "c", "d"]
1999
+ # ['a', 'b', 'c', 'd'].fill(1...-2) {|e| e.to_s } # => ["a", "1", "c", "d"]
2000
+ #
2001
+ # * If the range is endless (see [Endless
2002
+ # Ranges](rdoc-ref:Range@Endless+Ranges)), replaces elements to the end of
2003
+ # `self`:
2004
+ #
2005
+ # ['a', 'b', 'c', 'd'].fill('-', 1..) # => ["a", "-", "-", "-"]
2006
+ # ['a', 'b', 'c', 'd'].fill(1..) {|e| e.to_s } # => ["a", "1", "2", "3"]
2007
+ #
2008
+ # * If the range is beginless (see [Beginless
2009
+ # Ranges](rdoc-ref:Range@Beginless+Ranges)), replaces elements from the
2010
+ # beginning of `self`:
2011
+ #
2012
+ # ['a', 'b', 'c', 'd'].fill('-', ..2) # => ["-", "-", "-", "d"]
2013
+ # ['a', 'b', 'c', 'd'].fill(..2) {|e| e.to_s } # => ["0", "1", "2", "d"]
2014
+ #
2015
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
2016
+ #
2017
+ def fill: (E object, ?int? start, ?int? length) -> self
2018
+ | (E object, range[int?] range) -> self
2019
+ | (?int? start, ?int? length) { (Integer index) -> E } -> self
2020
+ | (range[int?] range) { (Integer index) -> E } -> self
2021
+
2022
+ # <!-- rdoc-file=array.c -->
2023
+ # With a block given, calls the block with each element of `self`; returns a new
2024
+ # array containing those elements of `self` for which the block returns a truthy
2025
+ # value:
2026
+ #
2027
+ # a = [:foo, 'bar', 2, :bam]
2028
+ # a.select {|element| element.to_s.start_with?('b') }
2029
+ # # => ["bar", :bam]
2030
+ #
2031
+ # With no block given, returns a new Enumerator.
2032
+ #
2033
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
2034
+ #
2035
+ alias filter select
2036
+
2037
+ # <!-- rdoc-file=array.c -->
2038
+ # With a block given, calls the block with each element of `self`; removes from
2039
+ # `self` those elements for which the block returns `false` or `nil`.
2040
+ #
2041
+ # Returns `self` if any elements were removed:
2042
+ #
2043
+ # a = [:foo, 'bar', 2, :bam]
2044
+ # a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
2045
+ #
2046
+ # Returns `nil` if no elements were removed.
2047
+ #
2048
+ # With no block given, returns a new Enumerator.
2049
+ #
2050
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
2051
+ #
2052
+ alias filter! select!
2053
+
2054
+ # <!--
2055
+ # rdoc-file=array.c
2056
+ # - find(if_none_proc = nil) {|element| ... } -> object or nil
2057
+ # - find(if_none_proc = nil) -> enumerator
2058
+ # -->
2059
+ # Returns the first element for which the block returns a truthy value.
2060
+ #
2061
+ # With a block given, calls the block with successive elements of the array;
2062
+ # returns the first element for which the block returns a truthy value:
2063
+ #
2064
+ # [1, 3, 5].find {|element| element > 2} # => 3
2065
+ #
2066
+ # If no such element is found, calls `if_none_proc` and returns its return
2067
+ # value.
2068
+ #
2069
+ # [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1
2070
+ #
2071
+ # With no block given, returns an Enumerator.
2072
+ #
2073
+ def find: () { (E) -> boolish } -> E?
2074
+ | () -> Enumerator[E, E?]
2075
+ | [T] (Enumerable::_NotFound[T]? ifnone) { (E) -> boolish } -> (E | T)
2076
+ | [T] (Enumerable::_NotFound[T]? ifnone) -> Enumerator[E, E | T]
2077
+
2078
+ # <!--
2079
+ # rdoc-file=array.c
2080
+ # - find_index(object) -> integer or nil
2081
+ # - find_index {|element| ... } -> integer or nil
2082
+ # - find_index -> new_enumerator
2083
+ # - index(object) -> integer or nil
2084
+ # - index {|element| ... } -> integer or nil
2085
+ # - index -> new_enumerator
2086
+ # -->
2087
+ # Returns the zero-based integer index of a specified element, or `nil`.
2088
+ #
2089
+ # With only argument `object` given, returns the index of the first element
2090
+ # `element` for which <code>object == element</code>:
2091
+ #
2092
+ # a = [:foo, 'bar', 2, 'bar']
2093
+ # a.index('bar') # => 1
2094
+ #
2095
+ # Returns `nil` if no such element found.
2096
+ #
2097
+ # With only a block given, calls the block with each successive element; returns
2098
+ # the index of the first element for which the block returns a truthy value:
2099
+ #
2100
+ # a = [:foo, 'bar', 2, 'bar']
2101
+ # a.index {|element| element == 'bar' } # => 1
2102
+ #
2103
+ # Returns `nil` if the block never returns a truthy value.
2104
+ #
2105
+ # With neither an argument nor a block given, returns a new Enumerator.
2106
+ #
2107
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2108
+ #
2109
+ def find_index: (untyped object) -> Integer? # where E: RBS::Ops::_Equal
2110
+ | () { (E element) -> boolish } -> Integer?
2111
+ | () -> Enumerator[E, Integer?]
2112
+
2113
+ # <!--
2114
+ # rdoc-file=array.rb
2115
+ # - first -> object or nil
2116
+ # - first(count) -> new_array
2117
+ # -->
2118
+ # Returns elements from `self`, or `nil`; does not modify `self`.
2119
+ #
2120
+ # With no argument given, returns the first element (if available):
2121
+ #
2122
+ # a = [:foo, 'bar', 2]
2123
+ # a.first # => :foo
2124
+ # a # => [:foo, "bar", 2]
2125
+ #
2126
+ # If `self` is empty, returns `nil`.
2127
+ #
2128
+ # [].first # => nil
2129
+ #
2130
+ # With a non-negative integer argument `count` given, returns the first `count`
2131
+ # elements (as available) in a new array:
2132
+ #
2133
+ # a.first(0) # => []
2134
+ # a.first(2) # => [:foo, "bar"]
2135
+ # a.first(50) # => [:foo, "bar", 2]
2136
+ #
2137
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2138
+ #
2139
+ def first: %a{implicitly-returns-nil} () -> E
2140
+ | (int count) -> Array[E]
2141
+
2142
+ # <!--
2143
+ # rdoc-file=array.c
2144
+ # - flatten(depth = nil) -> new_array
2145
+ # -->
2146
+ # Returns a new array that is a recursive flattening of `self` to `depth` levels
2147
+ # of recursion; `depth` must be an [integer-convertible
2148
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects) or
2149
+ # `nil`. At each level of recursion:
2150
+ #
2151
+ # * Each element that is an array is "flattened" (that is, replaced by its
2152
+ # individual array elements).
2153
+ # * Each element that is not an array is unchanged (even if the element is an
2154
+ # object that has instance method `flatten`).
2155
+ #
2156
+ # With non-negative integer argument `depth`, flattens recursively through
2157
+ # `depth` levels:
2158
+ #
2159
+ # a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ]
2160
+ # a # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>]
2161
+ # a.flatten(0) # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>]
2162
+ # a.flatten(1 ) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2163
+ # a.flatten(1.1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2164
+ # a.flatten(2) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2165
+ # a.flatten(3) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2166
+ #
2167
+ # With `nil` or negative `depth`, flattens all levels.
2168
+ #
2169
+ # a.flatten # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2170
+ # a.flatten(-1) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2171
+ #
2172
+ # Related: Array#flatten!; see also [Methods for
2173
+ # Converting](rdoc-ref:Array@Methods+for+Converting).
2174
+ #
2175
+ def flatten: (?int? level) -> Array[untyped]
2176
+
2177
+ # <!--
2178
+ # rdoc-file=array.c
2179
+ # - flatten!(depth = nil) -> self or nil
2180
+ # -->
2181
+ # Returns `self` as a recursively flattening of `self` to `depth` levels of
2182
+ # recursion; `depth` must be an [integer-convertible
2183
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects), or
2184
+ # `nil`. At each level of recursion:
2185
+ #
2186
+ # * Each element that is an array is "flattened" (that is, replaced by its
2187
+ # individual array elements).
2188
+ # * Each element that is not an array is unchanged (even if the element is an
2189
+ # object that has instance method `flatten`).
2190
+ #
2191
+ # Returns `nil` if no elements were flattened.
2192
+ #
2193
+ # With non-negative integer argument `depth`, flattens recursively through
2194
+ # `depth` levels:
2195
+ #
2196
+ # a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ]
2197
+ # a # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>]
2198
+ # a.dup.flatten!(1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2199
+ # a.dup.flatten!(1.1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2200
+ # a.dup.flatten!(2) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2201
+ # a.dup.flatten!(3) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2202
+ #
2203
+ # With `nil` or negative argument `depth`, flattens all levels:
2204
+ #
2205
+ # a.dup.flatten! # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2206
+ # a.dup.flatten!(-1) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
2207
+ #
2208
+ # Related: Array#flatten; see also [Methods for
2209
+ # Assigning](rdoc-ref:Array@Methods+for+Assigning).
2210
+ #
2211
+ def flatten!: (?int? level) -> self?
2212
+
2213
+ # <!--
2214
+ # rdoc-file=array.c
2215
+ # - freeze -> self
2216
+ # -->
2217
+ # Freezes `self` (if not already frozen); returns `self`:
2218
+ #
2219
+ # a = []
2220
+ # a.frozen? # => false
2221
+ # a.freeze
2222
+ # a.frozen? # => true
2223
+ #
2224
+ # No further changes may be made to `self`; raises FrozenError if a change is
2225
+ # attempted.
2226
+ #
2227
+ # Related: Kernel#frozen?.
2228
+ #
2229
+ def freeze: () -> self
2230
+
2231
+ # <!--
2232
+ # rdoc-file=array.c
2233
+ # - hash -> integer
2234
+ # -->
2235
+ # Returns the integer hash value for `self`.
2236
+ #
2237
+ # Two arrays with the same content will have the same hash value (and will
2238
+ # compare using eql?):
2239
+ #
2240
+ # ['a', 'b'].hash == ['a', 'b'].hash # => true
2241
+ # ['a', 'b'].hash == ['a', 'c'].hash # => false
2242
+ # ['a', 'b'].hash == ['a'].hash # => false
2243
+ #
2244
+ def hash: () -> Integer # where E: _Hash
2245
+
2246
+ # <!--
2247
+ # rdoc-file=array.c
2248
+ # - include?(object) -> true or false
2249
+ # -->
2250
+ # Returns whether for some element `element` in `self`, <code>object ==
2251
+ # element</code>:
2252
+ #
2253
+ # [0, 1, 2].include?(2) # => true
2254
+ # [0, 1, 2].include?(2.0) # => true
2255
+ # [0, 1, 2].include?(2.1) # => false
2256
+ #
2257
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2258
+ #
2259
+ def include?: (untyped object) -> bool # where E: RBS::Ops::_Equals
2260
+
2261
+ # <!-- rdoc-file=array.c -->
2262
+ # Returns the zero-based integer index of a specified element, or `nil`.
2263
+ #
2264
+ # With only argument `object` given, returns the index of the first element
2265
+ # `element` for which <code>object == element</code>:
2266
+ #
2267
+ # a = [:foo, 'bar', 2, 'bar']
2268
+ # a.index('bar') # => 1
2269
+ #
2270
+ # Returns `nil` if no such element found.
2271
+ #
2272
+ # With only a block given, calls the block with each successive element; returns
2273
+ # the index of the first element for which the block returns a truthy value:
2274
+ #
2275
+ # a = [:foo, 'bar', 2, 'bar']
2276
+ # a.index {|element| element == 'bar' } # => 1
2277
+ #
2278
+ # Returns `nil` if the block never returns a truthy value.
2279
+ #
2280
+ # With neither an argument nor a block given, returns a new Enumerator.
2281
+ #
2282
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2283
+ #
2284
+ alias index find_index
2285
+
2286
+ # <!--
2287
+ # rdoc-file=array.c
2288
+ # - insert(index, *objects) -> self
2289
+ # -->
2290
+ # Inserts the given `objects` as elements of `self`; returns `self`.
2291
+ #
2292
+ # When `index` is non-negative, inserts `objects` *before* the element at offset
2293
+ # `index`:
2294
+ #
2295
+ # a = ['a', 'b', 'c'] # => ["a", "b", "c"]
2296
+ # a.insert(1, :x, :y, :z) # => ["a", :x, :y, :z, "b", "c"]
2297
+ #
2298
+ # Extends the array if `index` is beyond the array (<code>index >=
2299
+ # self.size</code>):
2300
+ #
2301
+ # a = ['a', 'b', 'c'] # => ["a", "b", "c"]
2302
+ # a.insert(5, :x, :y, :z) # => ["a", "b", "c", nil, nil, :x, :y, :z]
2303
+ #
2304
+ # When `index` is negative, inserts `objects` *after* the element at offset
2305
+ # <code>index + self.size</code>:
2306
+ #
2307
+ # a = ['a', 'b', 'c'] # => ["a", "b", "c"]
2308
+ # a.insert(-2, :x, :y, :z) # => ["a", "b", :x, :y, :z, "c"]
2309
+ #
2310
+ # With no `objects` given, does nothing:
2311
+ #
2312
+ # a = ['a', 'b', 'c'] # => ["a", "b", "c"]
2313
+ # a.insert(1) # => ["a", "b", "c"]
2314
+ # a.insert(50) # => ["a", "b", "c"]
2315
+ # a.insert(-50) # => ["a", "b", "c"]
2316
+ #
2317
+ # Raises IndexError if `objects` are given and `index` is negative and out of
2318
+ # range.
2319
+ #
2320
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
2321
+ #
2322
+ def insert: (int index, *E objects) -> self
2323
+
2324
+ # <!--
2325
+ # rdoc-file=array.c
2326
+ # - inspect -> new_string
2327
+ # - to_s -> new_string
2328
+ # -->
2329
+ # Returns the new string formed by calling method <code>#inspect</code> on each
2330
+ # array element:
2331
+ #
2332
+ # a = [:foo, 'bar', 2]
2333
+ # a.inspect # => "[:foo, \"bar\", 2]"
2334
+ #
2335
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
2336
+ #
2337
+ def inspect: () -> String # where E: _Inspect
2338
+
2339
+ # <!--
2340
+ # rdoc-file=array.c
2341
+ # - intersect?(other_array) -> true or false
2342
+ # -->
2343
+ # Returns whether `other_array` has at least one element that is
2344
+ # <code>#eql?</code> to some element of `self`:
2345
+ #
2346
+ # [1, 2, 3].intersect?([3, 4, 5]) # => true
2347
+ # [1, 2, 3].intersect?([4, 5, 6]) # => false
2348
+ #
2349
+ # Each element must correctly implement method <code>#hash</code>.
2350
+ #
2351
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2352
+ #
2353
+ def intersect?: (array[untyped] other_array) -> bool # where E: _Eql?
2354
+
2355
+ # <!--
2356
+ # rdoc-file=array.c
2357
+ # - intersection(*other_arrays) -> new_array
2358
+ # -->
2359
+ # Returns a new array containing each element in `self` that is
2360
+ # <code>#eql?</code> to at least one element in each of the given
2361
+ # `other_arrays`; duplicates are omitted:
2362
+ #
2363
+ # [0, 0, 1, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
2364
+ #
2365
+ # Each element must correctly implement method <code>#hash</code>.
2366
+ #
2367
+ # Order from `self` is preserved:
2368
+ #
2369
+ # [0, 1, 2].intersection([2, 1, 0]) # => [0, 1, 2]
2370
+ #
2371
+ # Returns a copy of `self` if no arguments are given.
2372
+ #
2373
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
2374
+ #
2375
+ def intersection: (*array[untyped] other_arrays) -> Array[E] # where E: _Eql?
2376
+
2377
+ # <!--
2378
+ # rdoc-file=array.c
2379
+ # - join(separator = $,) -> new_string
2380
+ # -->
2381
+ # Returns the new string formed by joining the converted elements of `self`; for
2382
+ # each element `element`:
2383
+ #
2384
+ # * Converts recursively using <code>element.join(separator)</code> if
2385
+ # `element` is a <code>kind_of?(Array)</code>.
2386
+ # * Otherwise, converts using <code>element.to_s</code>.
2387
+ #
2388
+ # With no argument given, joins using the output field separator,
2389
+ # <code>$,</code>:
2390
+ #
2391
+ # a = [:foo, 'bar', 2]
2392
+ # $, # => nil
2393
+ # a.join # => "foobar2"
2394
+ #
2395
+ # With string argument `separator` given, joins using that separator:
2396
+ #
2397
+ # a = [:foo, 'bar', 2]
2398
+ # a.join("\n") # => "foo\nbar\n2"
2399
+ #
2400
+ # Joins recursively for nested arrays:
2401
+ #
2402
+ # a = [:foo, [:bar, [:baz, :bat]]]
2403
+ # a.join # => "foobarbazbat"
2404
+ #
2405
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
2406
+ #
2407
+ def join: (?string? separator) -> String # where E: _ToS
2408
+
2409
+ # <!--
2410
+ # rdoc-file=array.c
2411
+ # - keep_if {|element| ... } -> self
2412
+ # - keep_if -> new_enumerator
2413
+ # -->
2414
+ # With a block given, calls the block with each element of `self`; removes the
2415
+ # element from `self` if the block does not return a truthy value:
2416
+ #
2417
+ # a = [:foo, 'bar', 2, :bam]
2418
+ # a.keep_if {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
2419
+ #
2420
+ # With no block given, returns a new Enumerator.
2421
+ #
2422
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
2423
+ #
2424
+ def keep_if: () { (E element) -> boolish } -> self
2425
+ | () -> Enumerator[E, self]
2426
+
2427
+ # <!--
2428
+ # rdoc-file=array.rb
2429
+ # - last -> last_object or nil
2430
+ # - last(count) -> new_array
2431
+ # -->
2432
+ # Returns elements from `self`, or `nil`; `self` is not modified.
2433
+ #
2434
+ # With no argument given, returns the last element, or `nil` if `self` is empty:
2435
+ #
2436
+ # a = [:foo, 'bar', 2]
2437
+ # a.last # => 2
2438
+ # a # => [:foo, "bar", 2]
2439
+ # [].last # => nil
2440
+ #
2441
+ # With non-negative integer argument `count` given, returns a new array
2442
+ # containing the trailing `count` elements of `self`, as available:
2443
+ #
2444
+ # a = [:foo, 'bar', 2]
2445
+ # a.last(2) # => ["bar", 2]
2446
+ # a.last(50) # => [:foo, "bar", 2]
2447
+ # a.last(0) # => []
2448
+ # [].last(3) # => []
2449
+ #
2450
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
2451
+ #
2452
+ def last: %a{implicitly-returns-nil} () -> E
2453
+ | (int count) -> Array[E]
2454
+
2455
+ # <!--
2456
+ # rdoc-file=array.c
2457
+ # - length -> integer
2458
+ # - size -> integer
2459
+ # -->
2460
+ # Returns the count of elements in `self`:
2461
+ #
2462
+ # [0, 1, 2].length # => 3
2463
+ # [].length # => 0
2464
+ #
2465
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2466
+ #
2467
+ def length: () -> Integer
2468
+
2469
+ # <!-- rdoc-file=array.c -->
2470
+ # With a block given, calls the block with each element of `self`; returns a new
2471
+ # array whose elements are the return values from the block:
2472
+ #
2473
+ # a = [:foo, 'bar', 2]
2474
+ # a1 = a.map {|element| element.class }
2475
+ # a1 # => [Symbol, String, Integer]
2476
+ #
2477
+ # With no block given, returns a new Enumerator.
2478
+ #
2479
+ # Related: #collect!; see also [Methods for
2480
+ # Converting](rdoc-ref:Array@Methods+for+Converting).
2481
+ #
2482
+ alias map collect
2483
+
2484
+ # <!-- rdoc-file=array.c -->
2485
+ # With a block given, calls the block with each element of `self` and replaces
2486
+ # the element with the block's return value; returns `self`:
2487
+ #
2488
+ # a = [:foo, 'bar', 2]
2489
+ # a.map! { |element| element.class } # => [Symbol, String, Integer]
2490
+ #
2491
+ # With no block given, returns a new Enumerator.
2492
+ #
2493
+ # Related: #collect; see also [Methods for
2494
+ # Converting](rdoc-ref:Array@Methods+for+Converting).
2495
+ #
2496
+ alias map! collect!
2497
+
2498
+ # <!--
2499
+ # rdoc-file=array.c
2500
+ # - max -> element
2501
+ # - max(count) -> new_array
2502
+ # - max {|a, b| ... } -> element
2503
+ # - max(count) {|a, b| ... } -> new_array
2504
+ # -->
2505
+ # Returns one of the following:
2506
+ #
2507
+ # * The maximum-valued element from `self`.
2508
+ # * A new array of maximum-valued elements from `self`.
2509
+ #
2510
+ # Does not modify `self`.
2511
+ #
2512
+ # With no block given, each element in `self` must respond to method
2513
+ # <code>#<=></code> with a numeric.
2514
+ #
2515
+ # With no argument and no block, returns the element in `self` having the
2516
+ # maximum value per method <code>#<=></code>:
2517
+ #
2518
+ # [1, 0, 3, 2].max # => 3
2519
+ #
2520
+ # With non-negative numeric argument `count` and no block, returns a new array
2521
+ # with at most `count` elements, in descending order, per method
2522
+ # <code>#<=></code>:
2523
+ #
2524
+ # [1, 0, 3, 2].max(3) # => [3, 2, 1]
2525
+ # [1, 0, 3, 2].max(3.0) # => [3, 2, 1]
2526
+ # [1, 0, 3, 2].max(9) # => [3, 2, 1, 0]
2527
+ # [1, 0, 3, 2].max(0) # => []
2528
+ #
2529
+ # With a block given, the block must return a numeric.
2530
+ #
2531
+ # With a block and no argument, calls the block <code>self.size - 1</code> times
2532
+ # to compare elements; returns the element having the maximum value per the
2533
+ # block:
2534
+ #
2535
+ # ['0', '', '000', '00'].max {|a, b| a.size <=> b.size }
2536
+ # # => "000"
2537
+ #
2538
+ # With non-negative numeric argument `count` and a block, returns a new array
2539
+ # with at most `count` elements, in descending order, per the block:
2540
+ #
2541
+ # ['0', '', '000', '00'].max(2) {|a, b| a.size <=> b.size }
2542
+ # # => ["000", "00"]
2543
+ #
2544
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
2545
+ #
2546
+ def max: %a{implicitly-returns-nil} () -> E # where E: Comparable::_WithSpaceshipOperator
2547
+ | %a{implicitly-returns-nil} () { (E a, E b) -> Comparable::_CompareToZero } -> E
2548
+ | %a{implicitly-returns-nil} %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> E
2549
+ | (int count) -> Array[E] # where E: Comparable::_WithSpaceshipOperator
2550
+ | (int count) { (E a, E b) -> Comparable::_CompareToZero } -> Array[E]
2551
+ | %a{warning: returning `nil` will always raise at runtime} (int count) { (E a, E b) -> Comparable::_CompareToZero? } -> Array[E]
2552
+
2553
+ # <!--
2554
+ # rdoc-file=array.c
2555
+ # - min -> element
2556
+ # - min(count) -> new_array
2557
+ # - min {|a, b| ... } -> element
2558
+ # - min(count) {|a, b| ... } -> new_array
2559
+ # -->
2560
+ # Returns one of the following:
2561
+ #
2562
+ # * The minimum-valued element from `self`.
2563
+ # * A new array of minimum-valued elements from `self`.
2564
+ #
2565
+ # Does not modify `self`.
2566
+ #
2567
+ # With no block given, each element in `self` must respond to method
2568
+ # <code>#<=></code> with a numeric.
2569
+ #
2570
+ # With no argument and no block, returns the element in `self` having the
2571
+ # minimum value per method <code>#<=></code>:
2572
+ #
2573
+ # [1, 0, 3, 2].min # => 0
2574
+ #
2575
+ # With non-negative numeric argument `count` and no block, returns a new array
2576
+ # with at most `count` elements, in ascending order, per method
2577
+ # <code>#<=></code>:
2578
+ #
2579
+ # [1, 0, 3, 2].min(3) # => [0, 1, 2]
2580
+ # [1, 0, 3, 2].min(3.0) # => [0, 1, 2]
2581
+ # [1, 0, 3, 2].min(9) # => [0, 1, 2, 3]
2582
+ # [1, 0, 3, 2].min(0) # => []
2583
+ #
2584
+ # With a block given, the block must return a numeric.
2585
+ #
2586
+ # With a block and no argument, calls the block <code>self.size - 1</code> times
2587
+ # to compare elements; returns the element having the minimum value per the
2588
+ # block:
2589
+ #
2590
+ # ['0', '', '000', '00'].min {|a, b| a.size <=> b.size }
2591
+ # # => ""
2592
+ #
2593
+ # With non-negative numeric argument `count` and a block, returns a new array
2594
+ # with at most `count` elements, in ascending order, per the block:
2595
+ #
2596
+ # ['0', '', '000', '00'].min(2) {|a, b| a.size <=> b.size }
2597
+ # # => ["", "0"]
2598
+ #
2599
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
2600
+ #
2601
+ def min: %a{implicitly-returns-nil} () -> E # where E: Comparable::_WithSpaceshipOperator
2602
+ | %a{implicitly-returns-nil} () { (E a, E b) -> Comparable::_CompareToZero } -> E
2603
+ | %a{implicitly-returns-nil} %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> E
2604
+ | (int count) -> Array[E] # where E: Comparable::_WithSpaceshipOperator
2605
+ | (int count) { (E a, E b) -> Comparable::_CompareToZero } -> Array[E]
2606
+ | %a{warning: returning `nil` will always raise at runtime} (int count) { (E a, E b) -> Comparable::_CompareToZero? } -> Array[E]
2607
+
2608
+ # <!--
2609
+ # rdoc-file=array.c
2610
+ # - minmax -> array
2611
+ # - minmax {|a, b| ... } -> array
2612
+ # -->
2613
+ # Returns a 2-element array containing the minimum-valued and maximum-valued
2614
+ # elements from `self`; does not modify `self`.
2615
+ #
2616
+ # With no block given, the minimum and maximum values are determined using
2617
+ # method <code>#<=></code>:
2618
+ #
2619
+ # [1, 0, 3, 2].minmax # => [0, 3]
2620
+ #
2621
+ # With a block given, the block must return a numeric; the block is called
2622
+ # <code>self.size - 1</code> times to compare elements; returns the elements
2623
+ # having the minimum and maximum values per the block:
2624
+ #
2625
+ # ['0', '', '000', '00'].minmax {|a, b| a.size <=> b.size }
2626
+ # # => ["", "000"]
2627
+ #
2628
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
2629
+ #
2630
+ def minmax: () -> [ E?, E? ] # where E: Comparable::_WithSpaceshipOperator
2631
+ | () { (E a, E b) -> Comparable::_CompareToZero } -> [ E?, E? ]
2632
+ | %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> [ E?, E? ]
2633
+
2634
+ # <!--
2635
+ # rdoc-file=array.c
2636
+ # - none? -> true or false
2637
+ # - none?(object) -> true or false
2638
+ # - none? {|element| ... } -> true or false
2639
+ # -->
2640
+ # Returns `true` if no element of `self` meets a given criterion, `false`
2641
+ # otherwise.
2642
+ #
2643
+ # With no block given and no argument, returns `true` if `self` has no truthy
2644
+ # elements, `false` otherwise:
2645
+ #
2646
+ # [nil, false].none? # => true
2647
+ # [nil, 0, false].none? # => false
2648
+ # [].none? # => true
2649
+ #
2650
+ # With argument `object` given, returns `false` if for any element `element`,
2651
+ # <code>object === element</code>; `true` otherwise:
2652
+ #
2653
+ # ['food', 'drink'].none?(/bar/) # => true
2654
+ # ['food', 'drink'].none?(/foo/) # => false
2655
+ # [].none?(/foo/) # => true
2656
+ # [0, 1, 2].none?(3) # => true
2657
+ # [0, 1, 2].none?(1) # => false
2658
+ #
2659
+ # With a block given, calls the block with each element in `self`; returns
2660
+ # `true` if the block returns no truthy value, `false` otherwise:
2661
+ #
2662
+ # [0, 1, 2].none? {|element| element > 3 } # => true
2663
+ # [0, 1, 2].none? {|element| element > 1 } # => false
2664
+ #
2665
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2666
+ #
2667
+ def none?: () -> bool
2668
+ | (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
2669
+ | () { (E element) -> boolish } -> bool
2670
+
2671
+ # <!--
2672
+ # rdoc-file=array.c
2673
+ # - one? -> true or false
2674
+ # - one? {|element| ... } -> true or false
2675
+ # - one?(object) -> true or false
2676
+ # -->
2677
+ # Returns `true` if exactly one element of `self` meets a given criterion.
2678
+ #
2679
+ # With no block given and no argument, returns `true` if `self` has exactly one
2680
+ # truthy element, `false` otherwise:
2681
+ #
2682
+ # [nil, 0].one? # => true
2683
+ # [0, 0].one? # => false
2684
+ # [nil, nil].one? # => false
2685
+ # [].one? # => false
2686
+ #
2687
+ # With a block given, calls the block with each element in `self`; returns
2688
+ # `true` if the block a truthy value for exactly one element, `false` otherwise:
2689
+ #
2690
+ # [0, 1, 2].one? {|element| element > 0 } # => false
2691
+ # [0, 1, 2].one? {|element| element > 1 } # => true
2692
+ # [0, 1, 2].one? {|element| element > 2 } # => false
2693
+ #
2694
+ # With argument `object` given, returns `true` if for exactly one element
2695
+ # `element`, <code>object === element</code>; `false` otherwise:
2696
+ #
2697
+ # [0, 1, 2].one?(0) # => true
2698
+ # [0, 0, 1].one?(0) # => false
2699
+ # [1, 1, 2].one?(0) # => false
2700
+ # ['food', 'drink'].one?(/bar/) # => false
2701
+ # ['food', 'drink'].one?(/foo/) # => true
2702
+ # [].one?(/foo/) # => false
2703
+ #
2704
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
2705
+ #
2706
+ def one?: () -> bool
2707
+ | (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
2708
+ | () { (E element) -> boolish } -> bool
2709
+
2710
+ # <!--
2711
+ # rdoc-file=pack.rb
2712
+ # - pack(template, buffer: nil) -> string
2713
+ # -->
2714
+ # Formats each element in `self` into a binary string; returns that string. See
2715
+ # [Packed Data](rdoc-ref:language/packed_data.rdoc).
2716
+ #
2717
+ def pack: (string fmt, ?buffer: String?) -> String
2718
+
2719
+ # <!--
2720
+ # rdoc-file=array.c
2721
+ # - permutation(count = self.size) {|permutation| ... } -> self
2722
+ # - permutation(count = self.size) -> new_enumerator
2723
+ # -->
2724
+ # Iterates over permutations of the elements of `self`; the order of
2725
+ # permutations is indeterminate.
2726
+ #
2727
+ # With a block and an in-range positive integer argument `count` (<code>0 <
2728
+ # count <= self.size</code>) given, calls the block with each permutation of
2729
+ # `self` of size `count`; returns `self`:
2730
+ #
2731
+ # a = [0, 1, 2]
2732
+ # perms = []
2733
+ # a.permutation(1) {|perm| perms.push(perm) }
2734
+ # perms # => [[0], [1], [2]]
2735
+ #
2736
+ # perms = []
2737
+ # a.permutation(2) {|perm| perms.push(perm) }
2738
+ # perms # => [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]
2739
+ #
2740
+ # perms = []
2741
+ # a.permutation(3) {|perm| perms.push(perm) }
2742
+ # perms # => [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
2743
+ #
2744
+ # When `count` is zero, calls the block once with a new empty array:
2745
+ #
2746
+ # perms = []
2747
+ # a.permutation(0) {|perm| perms.push(perm) }
2748
+ # perms # => [[]]
2749
+ #
2750
+ # When `count` is out of range (negative or larger than <code>self.size</code>),
2751
+ # does not call the block:
2752
+ #
2753
+ # a.permutation(-1) {|permutation| fail 'Cannot happen' }
2754
+ # a.permutation(4) {|permutation| fail 'Cannot happen' }
2755
+ #
2756
+ # With no block given, returns a new Enumerator.
2757
+ #
2758
+ # Related: [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
2759
+ #
2760
+ def permutation: (?int? count) { (Array[E] permutation) -> void } -> self
2761
+ | (?int? count) -> Enumerator[Array[E], self]
2762
+
2763
+ # <!--
2764
+ # rdoc-file=array.c
2765
+ # - pop -> object or nil
2766
+ # - pop(count) -> new_array
2767
+ # -->
2768
+ # Removes and returns trailing elements of `self`.
2769
+ #
2770
+ # With no argument given, removes and returns the last element, if available;
2771
+ # otherwise returns `nil`:
2772
+ #
2773
+ # a = [:foo, 'bar', 2]
2774
+ # a.pop # => 2
2775
+ # a # => [:foo, "bar"]
2776
+ # [].pop # => nil
2777
+ #
2778
+ # With non-negative integer argument `count` given, returns a new array
2779
+ # containing the trailing `count` elements of `self`, as available:
2780
+ #
2781
+ # a = [:foo, 'bar', 2]
2782
+ # a.pop(2) # => ["bar", 2]
2783
+ # a # => [:foo]
2784
+ #
2785
+ # a = [:foo, 'bar', 2]
2786
+ # a.pop(50) # => [:foo, "bar", 2]
2787
+ # a # => []
2788
+ #
2789
+ # Related: Array#push; see also [Methods for
2790
+ # Deleting](rdoc-ref:Array@Methods+for+Deleting).
2791
+ #
2792
+ def pop: () -> E?
2793
+ | (int count) -> Array[E]
2794
+
2795
+ # <!-- rdoc-file=array.c -->
2796
+ # Prepends the given `objects` to `self`:
2797
+ #
2798
+ # a = [:foo, 'bar', 2]
2799
+ # a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]
2800
+ #
2801
+ # Related: Array#shift; see also [Methods for
2802
+ # Assigning](rdoc-ref:Array@Methods+for+Assigning).
2803
+ #
2804
+ alias prepend unshift
2805
+
2806
+ # <!--
2807
+ # rdoc-file=array.c
2808
+ # - product(*other_arrays) -> new_array
2809
+ # - product(*other_arrays) {|combination| ... } -> self
2810
+ # -->
2811
+ # Computes all combinations of elements from all the arrays, including both
2812
+ # `self` and `other_arrays`:
2813
+ #
2814
+ # * The number of combinations is the product of the sizes of all the arrays,
2815
+ # including both `self` and `other_arrays`.
2816
+ # * The order of the returned combinations is indeterminate.
2817
+ #
2818
+ # With no block given, returns the combinations as an array of arrays:
2819
+ #
2820
+ # p = [0, 1].product([2, 3])
2821
+ # # => [[0, 2], [0, 3], [1, 2], [1, 3]]
2822
+ # p.size # => 4
2823
+ # p = [0, 1].product([2, 3], [4, 5])
2824
+ # # => [[0, 2, 4], [0, 2, 5], [0, 3, 4], [0, 3, 5], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3,...
2825
+ # p.size # => 8
2826
+ #
2827
+ # If `self` or any argument is empty, returns an empty array:
2828
+ #
2829
+ # [].product([2, 3], [4, 5]) # => []
2830
+ # [0, 1].product([2, 3], []) # => []
2831
+ #
2832
+ # If no argument is given, returns an array of 1-element arrays, each containing
2833
+ # an element of `self`:
2834
+ #
2835
+ # a.product # => [[0], [1], [2]]
2836
+ #
2837
+ # With a block given, calls the block with each combination; returns `self`:
2838
+ #
2839
+ # p = []
2840
+ # [0, 1].product([2, 3]) {|combination| p.push(combination) }
2841
+ # p # => [[0, 2], [0, 3], [1, 2], [1, 3]]
2842
+ #
2843
+ # If `self` or any argument is empty, does not call the block:
2844
+ #
2845
+ # [].product([2, 3], [4, 5]) {|combination| fail 'Cannot happen' }
2846
+ # # => []
2847
+ # [0, 1].product([2, 3], []) {|combination| fail 'Cannot happen' }
2848
+ # # => [0, 1]
2849
+ #
2850
+ # If no argument is given, calls the block with each element of `self` as a
2851
+ # 1-element array:
2852
+ #
2853
+ # p = []
2854
+ # [0, 1].product {|combination| p.push(combination) }
2855
+ # p # => [[0], [1]]
2856
+ #
2857
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
2858
+ #
2859
+ def product: () -> Array[[ E ]]
2860
+ | () { ([E] combination) -> void } -> self
2861
+ | [X] (array[X] other_ary) -> Array[[ E, X ]]
2862
+ | [X] (array[X] other_ary) { ([E, X] combination) -> void } -> self
2863
+ | [X, Y] (array[X] other_ary1, array[Y] other_ary2) -> Array[[ E, X, Y ]]
2864
+ | [X, Y] (array[X] other_ary1, array[Y] other_ary2) { ([E, X, Y] combination) -> void } -> self
2865
+ | [U] (*array[U] other_arys) -> Array[Array[E | U]]
2866
+ | [U] (*array[U] other_arys) { (Array[E | U] combination) -> void } -> self
2867
+
2868
+ # <!--
2869
+ # rdoc-file=array.c
2870
+ # - push(*objects) -> self
2871
+ # - append(*objects) -> self
2872
+ # -->
2873
+ # Appends each argument in `objects` to `self`; returns `self`:
2874
+ #
2875
+ # a = [:foo, 'bar', 2] # => [:foo, "bar", 2]
2876
+ # a.push(:baz, :bat) # => [:foo, "bar", 2, :baz, :bat]
2877
+ #
2878
+ # Appends each argument as a single element, even if it is another array:
2879
+ #
2880
+ # a = [:foo, 'bar', 2] # => [:foo, "bar", 2]
2881
+ # a.push([:baz, :bat], [:bam, :bad]) # => [:foo, "bar", 2, [:baz, :bat], [:bam, :bad]]
2882
+ #
2883
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
2884
+ #
2885
+ def push: (*E objects) -> self
2886
+
2887
+ # <!--
2888
+ # rdoc-file=array.c
2889
+ # - rassoc(object) -> found_array or nil
2890
+ # -->
2891
+ # Returns the first element `ele` in `self` such that `ele` is an array and
2892
+ # <code>ele[1] == object</code>:
2893
+ #
2894
+ # a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
2895
+ # a.rassoc(4) # => [2, 4]
2896
+ # a.rassoc(5) # => [4, 5, 6]
2897
+ #
2898
+ # Returns `nil` if no such element is found.
2899
+ #
2900
+ # Related: Array#assoc; see also [Methods for
2901
+ # Fetching](rdoc-ref:Array@Methods+for+Fetching).
2902
+ #
2903
+ def rassoc: (untyped object) -> Array[untyped]? # where E: _ToAry, object: _Equal
2904
+
2905
+ # <!--
2906
+ # rdoc-file=array.c
2907
+ # - reject {|element| ... } -> new_array
2908
+ # - reject -> new_enumerator
2909
+ # -->
2910
+ # With a block given, returns a new array whose elements are all those from
2911
+ # `self` for which the block returns `false` or `nil`:
2912
+ #
2913
+ # a = [:foo, 'bar', 2, 'bat']
2914
+ # a1 = a.reject {|element| element.to_s.start_with?('b') }
2915
+ # a1 # => [:foo, 2]
2916
+ #
2917
+ # With no block given, returns a new Enumerator.
2918
+ #
2919
+ # Related: [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
2920
+ #
2921
+ alias reject delete_if
2922
+
2923
+ # <!--
2924
+ # rdoc-file=array.c
2925
+ # - reject! {|element| ... } -> self or nil
2926
+ # - reject! -> new_enumerator
2927
+ # -->
2928
+ # With a block given, calls the block with each element of `self`; removes each
2929
+ # element for which the block returns a truthy value.
2930
+ #
2931
+ # Returns `self` if any elements removed:
2932
+ #
2933
+ # a = [:foo, 'bar', 2, 'bat']
2934
+ # a.reject! {|element| element.to_s.start_with?('b') } # => [:foo, 2]
2935
+ #
2936
+ # Returns `nil` if no elements removed.
2937
+ #
2938
+ # With no block given, returns a new Enumerator.
2939
+ #
2940
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
2941
+ #
2942
+ def reject!: () { (E item) -> boolish } -> self?
2943
+ | () -> Enumerator[E, self?]
2944
+
2945
+ # <!--
2946
+ # rdoc-file=array.c
2947
+ # - repeated_combination(size) {|combination| ... } -> self
2948
+ # - repeated_combination(size) -> new_enumerator
2949
+ # -->
2950
+ # With a block given, calls the block with each repeated combination of length
2951
+ # `size` of the elements of `self`; each combination is an array; returns
2952
+ # `self`. The order of the combinations is indeterminate.
2953
+ #
2954
+ # If a positive integer argument `size` is given, calls the block with each
2955
+ # `size`-tuple repeated combination of the elements of `self`. The number of
2956
+ # combinations is <code>(size+1)(size+2)/2</code>.
2957
+ #
2958
+ # Examples:
2959
+ #
2960
+ # * `size` is 1:
2961
+ #
2962
+ # c = []
2963
+ # [0, 1, 2].repeated_combination(1) {|combination| c.push(combination) }
2964
+ # c # => [[0], [1], [2]]
2965
+ #
2966
+ # * `size` is 2:
2967
+ #
2968
+ # c = []
2969
+ # [0, 1, 2].repeated_combination(2) {|combination| c.push(combination) }
2970
+ # c # => [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]
2971
+ #
2972
+ # If `size` is zero, calls the block once with an empty array.
2973
+ #
2974
+ # If `size` is negative, does not call the block:
2975
+ #
2976
+ # [0, 1, 2].repeated_combination(-1) {|combination| fail 'Cannot happen' }
2977
+ #
2978
+ # With no block given, returns a new Enumerator.
2979
+ #
2980
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
2981
+ #
2982
+ def repeated_combination: (int size) { (Array[E] combination) -> void } -> self
2983
+ | (int size) -> Enumerator[Array[E], self]
2984
+
2985
+ # <!--
2986
+ # rdoc-file=array.c
2987
+ # - repeated_permutation(size) {|permutation| ... } -> self
2988
+ # - repeated_permutation(size) -> new_enumerator
2989
+ # -->
2990
+ # With a block given, calls the block with each repeated permutation of length
2991
+ # `size` of the elements of `self`; each permutation is an array; returns
2992
+ # `self`. The order of the permutations is indeterminate.
2993
+ #
2994
+ # If a positive integer argument `size` is given, calls the block with each
2995
+ # `size`-tuple repeated permutation of the elements of `self`. The number of
2996
+ # permutations is <code>self.size**size</code>.
2997
+ #
2998
+ # Examples:
2999
+ #
3000
+ # * `size` is 1:
3001
+ #
3002
+ # p = []
3003
+ # [0, 1, 2].repeated_permutation(1) {|permutation| p.push(permutation) }
3004
+ # p # => [[0], [1], [2]]
3005
+ #
3006
+ # * `size` is 2:
3007
+ #
3008
+ # p = []
3009
+ # [0, 1, 2].repeated_permutation(2) {|permutation| p.push(permutation) }
3010
+ # p # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
3011
+ #
3012
+ # If `size` is zero, calls the block once with an empty array.
3013
+ #
3014
+ # If `size` is negative, does not call the block:
3015
+ #
3016
+ # [0, 1, 2].repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
3017
+ #
3018
+ # With no block given, returns a new Enumerator.
3019
+ #
3020
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
3021
+ #
3022
+ def repeated_permutation: (int size) { (Array[E] permutation) -> void } -> self
3023
+ | (int size) -> Enumerator[Array[E], self]
3024
+
3025
+ # <!-- rdoc-file=array.c -->
3026
+ # Replaces the elements of `self` with the elements of `other_array`, which must
3027
+ # be an [array-convertible
3028
+ # object](rdoc-ref:implicit_conversion.rdoc@Array-Convertible+Objects); returns
3029
+ # `self`:
3030
+ #
3031
+ # a = ['a', 'b', 'c'] # => ["a", "b", "c"]
3032
+ # a.replace(['d', 'e']) # => ["d", "e"]
3033
+ #
3034
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
3035
+ #
3036
+ def replace: (array[E] other_array) -> self
3037
+
3038
+ # <!--
3039
+ # rdoc-file=array.c
3040
+ # - reverse -> new_array
3041
+ # -->
3042
+ # Returns a new array containing the elements of `self` in reverse order:
3043
+ #
3044
+ # [0, 1, 2].reverse # => [2, 1, 0]
3045
+ #
3046
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
3047
+ #
3048
+ def reverse: () -> Array[E]
3049
+
3050
+ # <!--
3051
+ # rdoc-file=array.c
3052
+ # - reverse! -> self
3053
+ # -->
3054
+ # Reverses the order of the elements of `self`; returns `self`:
3055
+ #
3056
+ # a = [0, 1, 2]
3057
+ # a.reverse! # => [2, 1, 0]
3058
+ # a # => [2, 1, 0]
3059
+ #
3060
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
3061
+ #
3062
+ def reverse!: () -> self
3063
+
3064
+ # <!--
3065
+ # rdoc-file=array.c
3066
+ # - reverse_each {|element| ... } -> self
3067
+ # - reverse_each -> Enumerator
3068
+ # -->
3069
+ # When a block given, iterates backwards over the elements of `self`, passing,
3070
+ # in reverse order, each element to the block; returns `self`:
3071
+ #
3072
+ # a = []
3073
+ # [0, 1, 2].reverse_each {|element| a.push(element) }
3074
+ # a # => [2, 1, 0]
3075
+ #
3076
+ # Allows the array to be modified during iteration:
3077
+ #
3078
+ # a = ['a', 'b', 'c']
3079
+ # a.reverse_each {|element| a.clear if element.start_with?('b') }
3080
+ # a # => []
3081
+ #
3082
+ # When no block given, returns a new Enumerator.
3083
+ #
3084
+ # Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
3085
+ #
3086
+ def reverse_each: () { (E element) -> void } -> self
3087
+ | () -> Enumerator[E, self]
3088
+
3089
+ # <!--
3090
+ # rdoc-file=array.c
3091
+ # - rfind(if_none_proc = nil) {|element| ... } -> object or nil
3092
+ # - rfind(if_none_proc = nil) -> enumerator
3093
+ # -->
3094
+ # Returns the last element for which the block returns a truthy value.
3095
+ #
3096
+ # With a block given, calls the block with successive elements of the array in
3097
+ # reverse order; returns the first element for which the block returns a truthy
3098
+ # value:
3099
+ #
3100
+ # [1, 2, 3, 4, 5, 6].rfind {|element| element < 5} # => 4
3101
+ #
3102
+ # If no such element is found, calls `if_none_proc` and returns its return
3103
+ # value.
3104
+ #
3105
+ # [1, 2, 3, 4].rfind(proc {0}) {|element| element < -2} # => 0
3106
+ #
3107
+ # With no block given, returns an Enumerator.
3108
+ #
3109
+ def rfind: () { (E) -> boolish } -> E?
3110
+ | () -> Enumerator[E, E?]
3111
+ | [T] (Enumerable::_NotFound[T]? ifnone) { (E) -> boolish } -> (E | T)
3112
+ | [T] (Enumerable::_NotFound[T]? ifnone) -> Enumerator[E, E | T]
3113
+
3114
+ # <!--
3115
+ # rdoc-file=array.c
3116
+ # - rindex(object) -> integer or nil
3117
+ # - rindex {|element| ... } -> integer or nil
3118
+ # - rindex -> new_enumerator
3119
+ # -->
3120
+ # Returns the index of the last element for which <code>object ==
3121
+ # element</code>.
3122
+ #
3123
+ # With argument `object` given, returns the index of the last such element
3124
+ # found:
3125
+ #
3126
+ # a = [:foo, 'bar', 2, 'bar']
3127
+ # a.rindex('bar') # => 3
3128
+ #
3129
+ # Returns `nil` if no such object found.
3130
+ #
3131
+ # With a block given, calls the block with each successive element; returns the
3132
+ # index of the last element for which the block returns a truthy value:
3133
+ #
3134
+ # a = [:foo, 'bar', 2, 'bar']
3135
+ # a.rindex {|element| element == 'bar' } # => 3
3136
+ #
3137
+ # Returns `nil` if the block never returns a truthy value.
3138
+ #
3139
+ # When neither an argument nor a block is given, returns a new Enumerator.
3140
+ #
3141
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
3142
+ #
3143
+ def rindex: (untyped object) -> Integer? # where E: _Equal
3144
+ | () { (E element) -> boolish } -> Integer?
3145
+ | () -> Enumerator[E, Integer?]
3146
+
3147
+ # <!--
3148
+ # rdoc-file=array.c
3149
+ # - rotate(count = 1) -> new_array
3150
+ # -->
3151
+ # Returns a new array formed from `self` with elements rotated from one end to
3152
+ # the other.
3153
+ #
3154
+ # With non-negative numeric `count`, rotates elements from the beginning to the
3155
+ # end:
3156
+ #
3157
+ # [0, 1, 2, 3].rotate(2) # => [2, 3, 0, 1]
3158
+ # [0, 1, 2, 3].rotate(2.1) # => [2, 3, 0, 1]
3159
+ #
3160
+ # If `count` is large, uses <code>count % array.size</code> as the count:
3161
+ #
3162
+ # [0, 1, 2, 3].rotate(22) # => [2, 3, 0, 1]
3163
+ #
3164
+ # With a `count` of zero, rotates no elements:
3165
+ #
3166
+ # [0, 1, 2, 3].rotate(0) # => [0, 1, 2, 3]
3167
+ #
3168
+ # With negative numeric `count`, rotates in the opposite direction, from the end
3169
+ # to the beginning:
3170
+ #
3171
+ # [0, 1, 2, 3].rotate(-1) # => [3, 0, 1, 2]
3172
+ #
3173
+ # If `count` is small (far from zero), uses <code>count % array.size</code> as
3174
+ # the count:
3175
+ #
3176
+ # [0, 1, 2, 3].rotate(-21) # => [3, 0, 1, 2]
3177
+ #
3178
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3179
+ #
3180
+ def rotate: (?int count) -> Array[E]
3181
+
3182
+ # <!--
3183
+ # rdoc-file=array.c
3184
+ # - rotate!(count = 1) -> self
3185
+ # -->
3186
+ # Rotates `self` in place by moving elements from one end to the other; returns
3187
+ # `self`.
3188
+ #
3189
+ # With non-negative numeric `count`, rotates `count` elements from the beginning
3190
+ # to the end:
3191
+ #
3192
+ # [0, 1, 2, 3].rotate!(2) # => [2, 3, 0, 1]
3193
+ # [0, 1, 2, 3].rotate!(2.1) # => [2, 3, 0, 1]
3194
+ #
3195
+ # If `count` is large, uses <code>count % array.size</code> as the count:
3196
+ #
3197
+ # [0, 1, 2, 3].rotate!(21) # => [1, 2, 3, 0]
3198
+ #
3199
+ # If `count` is zero, rotates no elements:
3200
+ #
3201
+ # [0, 1, 2, 3].rotate!(0) # => [0, 1, 2, 3]
3202
+ #
3203
+ # With a negative numeric `count`, rotates in the opposite direction, from end
3204
+ # to beginning:
3205
+ #
3206
+ # [0, 1, 2, 3].rotate!(-1) # => [3, 0, 1, 2]
3207
+ #
3208
+ # If `count` is small (far from zero), uses <code>count % array.size</code> as
3209
+ # the count:
3210
+ #
3211
+ # [0, 1, 2, 3].rotate!(-21) # => [3, 0, 1, 2]
3212
+ #
3213
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
3214
+ #
3215
+ def rotate!: (?int count) -> self
3216
+
3217
+ # <!--
3218
+ # rdoc-file=array.rb
3219
+ # - sample(random: Random) -> object
3220
+ # - sample(count, random: Random) -> new_ary
3221
+ # -->
3222
+ # Returns random elements from `self`, as selected by the object given by the
3223
+ # keyword argument `random`.
3224
+ #
3225
+ # With no argument `count` given, returns one random element from `self`:
3226
+ #
3227
+ # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
3228
+ # a.sample # => 3
3229
+ # a.sample # => 8
3230
+ #
3231
+ # Returns `nil` if `self` is empty:
3232
+ #
3233
+ # [].sample # => nil
3234
+ #
3235
+ # With a non-negative numeric argument `count` given, returns a new array
3236
+ # containing `count` random elements from `self`:
3237
+ #
3238
+ # a.sample(3) # => [8, 9, 2]
3239
+ # a.sample(6) # => [9, 6, 0, 3, 1, 4]
3240
+ #
3241
+ # The order of the result array is unrelated to the order of `self`.
3242
+ #
3243
+ # Returns a new empty array if `self` is empty:
3244
+ #
3245
+ # [].sample(4) # => []
3246
+ #
3247
+ # May return duplicates in `self`:
3248
+ #
3249
+ # a = [1, 1, 1, 2, 2, 3]
3250
+ # a.sample(a.size) # => [1, 1, 3, 2, 1, 2]
3251
+ #
3252
+ # Returns no more than <code>a.size</code> elements (because no new duplicates
3253
+ # are introduced):
3254
+ #
3255
+ # a.sample(50) # => [6, 4, 1, 8, 5, 9, 0, 2, 3, 7]
3256
+ #
3257
+ # The object given with the keyword argument `random` is used as the random
3258
+ # number generator:
3259
+ #
3260
+ # a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
3261
+ # a.sample(random: Random.new(1)) # => 6
3262
+ # a.sample(4, random: Random.new(1)) # => [6, 10, 9, 2]
3263
+ #
3264
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3265
+ #
3266
+ def sample: %a{implicitly-returns-nil} (?random: _Rand) -> E
3267
+ | (int count, ?random: _Rand) -> Array[E]
3268
+
3269
+ # <!--
3270
+ # rdoc-file=array.c
3271
+ # - select {|element| ... } -> new_array
3272
+ # - select -> new_enumerator
3273
+ # - filter {|element| ... } -> new_array
3274
+ # - filter -> new_enumerator
3275
+ # -->
3276
+ # With a block given, calls the block with each element of `self`; returns a new
3277
+ # array containing those elements of `self` for which the block returns a truthy
3278
+ # value:
3279
+ #
3280
+ # a = [:foo, 'bar', 2, :bam]
3281
+ # a.select {|element| element.to_s.start_with?('b') }
3282
+ # # => ["bar", :bam]
3283
+ #
3284
+ # With no block given, returns a new Enumerator.
3285
+ #
3286
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3287
+ #
3288
+ def select: () { (E element) -> boolish } -> Array[E]
3289
+ | () -> Enumerator[E, Array[E]]
3290
+
3291
+ # <!--
3292
+ # rdoc-file=array.c
3293
+ # - select! {|element| ... } -> self or nil
3294
+ # - select! -> new_enumerator
3295
+ # - filter! {|element| ... } -> self or nil
3296
+ # - filter! -> new_enumerator
3297
+ # -->
3298
+ # With a block given, calls the block with each element of `self`; removes from
3299
+ # `self` those elements for which the block returns `false` or `nil`.
3300
+ #
3301
+ # Returns `self` if any elements were removed:
3302
+ #
3303
+ # a = [:foo, 'bar', 2, :bam]
3304
+ # a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
3305
+ #
3306
+ # Returns `nil` if no elements were removed.
3307
+ #
3308
+ # With no block given, returns a new Enumerator.
3309
+ #
3310
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
3311
+ #
3312
+ def select!: () { (E element) -> boolish } -> self?
3313
+ | () -> Enumerator[E, self?]
3314
+
3315
+ # <!--
3316
+ # rdoc-file=array.c
3317
+ # - shift -> object or nil
3318
+ # - shift(count) -> new_array or nil
3319
+ # -->
3320
+ # Removes and returns leading elements from `self`.
3321
+ #
3322
+ # With no argument, removes and returns one element, if available, or `nil`
3323
+ # otherwise:
3324
+ #
3325
+ # a = [0, 1, 2, 3]
3326
+ # a.shift # => 0
3327
+ # a # => [1, 2, 3]
3328
+ # [].shift # => nil
3329
+ #
3330
+ # With non-negative numeric argument `count` given, removes and returns the
3331
+ # first `count` elements:
3332
+ #
3333
+ # a = [0, 1, 2, 3]
3334
+ # a.shift(2) # => [0, 1]
3335
+ # a # => [2, 3]
3336
+ # a.shift(1.1) # => [2]
3337
+ # a # => [3]
3338
+ # a.shift(0) # => []
3339
+ # a # => [3]
3340
+ #
3341
+ # If `count` is large, removes and returns all elements:
3342
+ #
3343
+ # a = [0, 1, 2, 3]
3344
+ # a.shift(50) # => [0, 1, 2, 3]
3345
+ # a # => []
3346
+ #
3347
+ # If `self` is empty, returns a new empty array.
3348
+ #
3349
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
3350
+ #
3351
+ def shift: %a{implicitly-returns-nil} () -> E
3352
+ | (int count) -> Array[E]
3353
+
3354
+ # <!--
3355
+ # rdoc-file=array.rb
3356
+ # - shuffle(random: Random) -> new_array
3357
+ # -->
3358
+ # Returns a new array containing all elements from `self` in a random order, as
3359
+ # selected by the object given by the keyword argument `random`:
3360
+ #
3361
+ # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
3362
+ # a.shuffle # => [0, 8, 1, 9, 6, 3, 4, 7, 2, 5]
3363
+ # a.shuffle # => [8, 9, 0, 5, 1, 2, 6, 4, 7, 3]
3364
+ #
3365
+ # Duplicate elements are included:
3366
+ #
3367
+ # a = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
3368
+ # a.shuffle # => [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
3369
+ # a.shuffle # => [1, 1, 0, 0, 0, 1, 1, 0, 0, 1]
3370
+ #
3371
+ # The object given with the keyword argument `random` is used as the random
3372
+ # number generator.
3373
+ #
3374
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3375
+ #
3376
+ def shuffle: (?random: _Rand) -> Array[E]
3377
+
3378
+ # <!--
3379
+ # rdoc-file=array.rb
3380
+ # - shuffle!(random: Random) -> self
3381
+ # -->
3382
+ # Shuffles all elements in `self` into a random order, as selected by the object
3383
+ # given by the keyword argument `random`. Returns `self`:
3384
+ #
3385
+ # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
3386
+ # a.shuffle! # => [5, 3, 8, 7, 6, 1, 9, 4, 2, 0]
3387
+ # a.shuffle! # => [9, 4, 0, 6, 2, 8, 1, 5, 3, 7]
3388
+ #
3389
+ # Duplicate elements are included:
3390
+ #
3391
+ # a = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
3392
+ # a.shuffle! # => [1, 0, 0, 1, 1, 0, 1, 0, 0, 1]
3393
+ # a.shuffle! # => [0, 1, 0, 1, 1, 0, 1, 0, 1, 0]
3394
+ #
3395
+ # The object given with the keyword argument `random` is used as the random
3396
+ # number generator.
3397
+ #
3398
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
3399
+ #
3400
+ def shuffle!: (?random: _Rand) -> self
3401
+
3402
+ # <!-- rdoc-file=array.c -->
3403
+ # Returns the count of elements in `self`:
3404
+ #
3405
+ # [0, 1, 2].length # => 3
3406
+ # [].length # => 0
3407
+ #
3408
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
3409
+ #
3410
+ alias size length
3411
+
3412
+ # <!-- rdoc-file=array.c -->
3413
+ # Returns elements from `self`; does not modify `self`.
3414
+ #
3415
+ # In brief:
3416
+ #
3417
+ # a = [:foo, 'bar', 2]
3418
+ #
3419
+ # # Single argument index: returns one element.
3420
+ # a[0] # => :foo # Zero-based index.
3421
+ # a[-1] # => 2 # Negative index counts backwards from end.
3422
+ #
3423
+ # # Arguments start and length: returns an array.
3424
+ # a[1, 2] # => ["bar", 2]
3425
+ # a[-2, 2] # => ["bar", 2] # Negative start counts backwards from end.
3426
+ #
3427
+ # # Single argument range: returns an array.
3428
+ # a[0..1] # => [:foo, "bar"]
3429
+ # a[0..-2] # => [:foo, "bar"] # Negative range-begin counts backwards from end.
3430
+ # a[-2..2] # => ["bar", 2] # Negative range-end counts backwards from end.
3431
+ #
3432
+ # When a single integer argument `index` is given, returns the element at offset
3433
+ # `index`:
3434
+ #
3435
+ # a = [:foo, 'bar', 2]
3436
+ # a[0] # => :foo
3437
+ # a[2] # => 2
3438
+ # a # => [:foo, "bar", 2]
3439
+ #
3440
+ # If `index` is negative, counts backwards from the end of `self`:
3441
+ #
3442
+ # a = [:foo, 'bar', 2]
3443
+ # a[-1] # => 2
3444
+ # a[-2] # => "bar"
3445
+ #
3446
+ # If `index` is out of range, returns `nil`.
3447
+ #
3448
+ # When two Integer arguments `start` and `length` are given, returns a new array
3449
+ # of size `length` containing successive elements beginning at offset `start`:
3450
+ #
3451
+ # a = [:foo, 'bar', 2]
3452
+ # a[0, 2] # => [:foo, "bar"]
3453
+ # a[1, 2] # => ["bar", 2]
3454
+ #
3455
+ # If <code>start + length</code> is greater than <code>self.length</code>,
3456
+ # returns all elements from offset `start` to the end:
3457
+ #
3458
+ # a = [:foo, 'bar', 2]
3459
+ # a[0, 4] # => [:foo, "bar", 2]
3460
+ # a[1, 3] # => ["bar", 2]
3461
+ # a[2, 2] # => [2]
3462
+ #
3463
+ # If <code>start == self.size</code> and <code>length >= 0</code>, returns a new
3464
+ # empty array.
3465
+ #
3466
+ # If `length` is negative, returns `nil`.
3467
+ #
3468
+ # When a single Range argument `range` is given, treats <code>range.min</code>
3469
+ # as `start` above and <code>range.size</code> as `length` above:
3470
+ #
3471
+ # a = [:foo, 'bar', 2]
3472
+ # a[0..1] # => [:foo, "bar"]
3473
+ # a[1..2] # => ["bar", 2]
3474
+ #
3475
+ # Special case: If <code>range.start == a.size</code>, returns a new empty
3476
+ # array.
3477
+ #
3478
+ # If <code>range.end</code> is negative, calculates the end index from the end:
3479
+ #
3480
+ # a = [:foo, 'bar', 2]
3481
+ # a[0..-1] # => [:foo, "bar", 2]
3482
+ # a[0..-2] # => [:foo, "bar"]
3483
+ # a[0..-3] # => [:foo]
3484
+ #
3485
+ # If <code>range.start</code> is negative, calculates the start index from the
3486
+ # end:
3487
+ #
3488
+ # a = [:foo, 'bar', 2]
3489
+ # a[-1..2] # => [2]
3490
+ # a[-2..2] # => ["bar", 2]
3491
+ # a[-3..2] # => [:foo, "bar", 2]
3492
+ #
3493
+ # If <code>range.start</code> is larger than the array size, returns `nil`.
3494
+ #
3495
+ # a = [:foo, 'bar', 2]
3496
+ # a[4..1] # => nil
3497
+ # a[4..0] # => nil
3498
+ # a[4..-1] # => nil
3499
+ #
3500
+ # When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
3501
+ # an array of elements corresponding to the indexes produced by the sequence.
3502
+ #
3503
+ # a = ['--', 'data1', '--', 'data2', '--', 'data3']
3504
+ # a[(1..).step(2)] # => ["data1", "data2", "data3"]
3505
+ #
3506
+ # Unlike slicing with range, if the start or the end of the arithmetic sequence
3507
+ # is larger than array size, throws RangeError.
3508
+ #
3509
+ # a = ['--', 'data1', '--', 'data2', '--', 'data3']
3510
+ # a[(1..11).step(2)]
3511
+ # # RangeError (((1..11).step(2)) out of range)
3512
+ # a[(7..).step(2)]
3513
+ # # RangeError (((7..).step(2)) out of range)
3514
+ #
3515
+ # If given a single argument, and its type is not one of the listed, tries to
3516
+ # convert it to Integer, and raises if it is impossible:
3517
+ #
3518
+ # a = [:foo, 'bar', 2]
3519
+ # # Raises TypeError (no implicit conversion of Symbol into Integer):
3520
+ # a[:foo]
3521
+ #
3522
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3523
+ #
3524
+ alias slice []
3525
+
3526
+ # <!--
3527
+ # rdoc-file=array.c
3528
+ # - slice!(index) -> object or nil
3529
+ # - slice!(start, length) -> new_array or nil
3530
+ # - slice!(range) -> new_array or nil
3531
+ # -->
3532
+ # Removes and returns elements from `self`.
3533
+ #
3534
+ # With numeric argument `index` given, removes and returns the element at offset
3535
+ # `index`:
3536
+ #
3537
+ # a = ['a', 'b', 'c', 'd']
3538
+ # a.slice!(2) # => "c"
3539
+ # a # => ["a", "b", "d"]
3540
+ # a.slice!(2.1) # => "d"
3541
+ # a # => ["a", "b"]
3542
+ #
3543
+ # If `index` is negative, counts backwards from the end of `self`:
3544
+ #
3545
+ # a = ['a', 'b', 'c', 'd']
3546
+ # a.slice!(-2) # => "c"
3547
+ # a # => ["a", "b", "d"]
3548
+ #
3549
+ # If `index` is out of range, returns `nil`.
3550
+ #
3551
+ # With numeric arguments `start` and `length` given, removes `length` elements
3552
+ # from `self` beginning at zero-based offset `start`; returns the removed
3553
+ # objects in a new array:
3554
+ #
3555
+ # a = ['a', 'b', 'c', 'd']
3556
+ # a.slice!(1, 2) # => ["b", "c"]
3557
+ # a # => ["a", "d"]
3558
+ # a.slice!(0.1, 1.1) # => ["a"]
3559
+ # a # => ["d"]
3560
+ #
3561
+ # If `start` is negative, counts backwards from the end of `self`:
3562
+ #
3563
+ # a = ['a', 'b', 'c', 'd']
3564
+ # a.slice!(-2, 1) # => ["c"]
3565
+ # a # => ["a", "b", "d"]
3566
+ #
3567
+ # If `start` is out-of-range, returns `nil`:
3568
+ #
3569
+ # a = ['a', 'b', 'c', 'd']
3570
+ # a.slice!(5, 1) # => nil
3571
+ # a.slice!(-5, 1) # => nil
3572
+ #
3573
+ # If <code>start + length</code> exceeds the array size, removes and returns all
3574
+ # elements from offset `start` to the end:
3575
+ #
3576
+ # a = ['a', 'b', 'c', 'd']
3577
+ # a.slice!(2, 50) # => ["c", "d"]
3578
+ # a # => ["a", "b"]
3579
+ #
3580
+ # If <code>start == a.size</code> and `length` is non-negative, returns a new
3581
+ # empty array.
3582
+ #
3583
+ # If `length` is negative, returns `nil`.
3584
+ #
3585
+ # With Range argument `range` given, treats <code>range.min</code> as `start`
3586
+ # (as above) and <code>range.size</code> as `length` (as above):
3587
+ #
3588
+ # a = ['a', 'b', 'c', 'd']
3589
+ # a.slice!(1..2) # => ["b", "c"]
3590
+ # a # => ["a", "d"]
3591
+ #
3592
+ # If <code>range.start == a.size</code>, returns a new empty array:
3593
+ #
3594
+ # a = ['a', 'b', 'c', 'd']
3595
+ # a.slice!(4..5) # => []
3596
+ #
3597
+ # If <code>range.start</code> is larger than the array size, returns `nil`:
3598
+ #
3599
+ # a = ['a', 'b', 'c', 'd']
3600
+ # a.slice!(5..6) # => nil
3601
+ #
3602
+ # If <code>range.start</code> is negative, calculates the start index by
3603
+ # counting backwards from the end of `self`:
3604
+ #
3605
+ # a = ['a', 'b', 'c', 'd']
3606
+ # a.slice!(-2..2) # => ["c"]
3607
+ #
3608
+ # If <code>range.end</code> is negative, calculates the end index by counting
3609
+ # backwards from the end of `self`:
3610
+ #
3611
+ # a = ['a', 'b', 'c', 'd']
3612
+ # a.slice!(0..-2) # => ["a", "b", "c"]
3613
+ #
3614
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
3615
+ #
3616
+ def slice!: %a{implicitly-returns-nil} (int index) -> E
3617
+ | (int start, int length) -> Array[E]?
3618
+ | (range[int?] range) -> Array[E]?
3619
+
3620
+ # <!--
3621
+ # rdoc-file=array.c
3622
+ # - sort -> new_array
3623
+ # - sort {|a, b| ... } -> new_array
3624
+ # -->
3625
+ # Returns a new array containing the elements of `self`, sorted.
3626
+ #
3627
+ # With no block given, compares elements using operator <code>#<=></code> (see
3628
+ # Object#<=>):
3629
+ #
3630
+ # [0, 2, 3, 1].sort # => [0, 1, 2, 3]
3631
+ #
3632
+ # With a block given, calls the block with each combination of pairs of elements
3633
+ # from `self`; for each pair `a` and `b`, the block should return a numeric:
3634
+ #
3635
+ # * Negative when `b` is to follow `a`.
3636
+ # * Zero when `a` and `b` are equivalent.
3637
+ # * Positive when `a` is to follow `b`.
3638
+ #
3639
+ # Example:
3640
+ #
3641
+ # a = [3, 2, 0, 1]
3642
+ # a.sort {|a, b| a <=> b } # => [0, 1, 2, 3]
3643
+ # a.sort {|a, b| b <=> a } # => [3, 2, 1, 0]
3644
+ #
3645
+ # When the block returns zero, the order for `a` and `b` is indeterminate, and
3646
+ # may be unstable.
3647
+ #
3648
+ # See an example in Numeric#nonzero? for the idiom to sort more complex
3649
+ # structure.
3650
+ #
3651
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3652
+ #
3653
+ def sort: () -> Array[E] # where E: Comparable::_WithSpaceshipOperator
3654
+ | () { (E a, E b) -> Comparable::_CompareToZero } -> Array[E]
3655
+ | %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> Array[E]
3656
+
3657
+ # <!--
3658
+ # rdoc-file=array.c
3659
+ # - sort! -> self
3660
+ # - sort! {|a, b| ... } -> self
3661
+ # -->
3662
+ # Like Array#sort, but returns `self` with its elements sorted in place.
3663
+ #
3664
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
3665
+ #
3666
+ def sort!: () -> self # where E: Comparable::_WithSpaceshipOperator
3667
+ | () { (E a, E b) -> Comparable::_CompareToZero } -> self
3668
+ | %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> self
3669
+
3670
+ # <!--
3671
+ # rdoc-file=array.c
3672
+ # - sort_by! {|element| ... } -> self
3673
+ # - sort_by! -> new_enumerator
3674
+ # -->
3675
+ # With a block given, sorts the elements of `self` in place; returns self.
3676
+ #
3677
+ # Calls the block with each successive element; sorts elements based on the
3678
+ # values returned from the block:
3679
+ #
3680
+ # a = ['aaaa', 'bbb', 'cc', 'd']
3681
+ # a.sort_by! {|element| element.size }
3682
+ # a # => ["d", "cc", "bbb", "aaaa"]
3683
+ #
3684
+ # For duplicate values returned by the block, the ordering is indeterminate, and
3685
+ # may be unstable.
3686
+ #
3687
+ # With no block given, returns a new Enumerator.
3688
+ #
3689
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
3690
+ #
3691
+ def sort_by!: () { (E element) -> Comparable::_WithSpaceshipOperator } -> self
3692
+ | %a{warning: returning `nil` will always raise at runtime} () { (E element) -> Comparable::_WithSpaceshipOperator? } -> self
3693
+ | () -> Enumerator[E, self]
3694
+
3695
+ # <!--
3696
+ # rdoc-file=array.c
3697
+ # - sum(init = 0) -> object
3698
+ # - sum(init = 0) {|element| ... } -> object
3699
+ # -->
3700
+ # With no block given, returns the sum of `init` and all elements of `self`; for
3701
+ # array `array` and value `init`, equivalent to:
3702
+ #
3703
+ # sum = init
3704
+ # array.each {|element| sum += element }
3705
+ # sum
3706
+ #
3707
+ # For example, <code>[e0, e1, e2].sum</code> returns <code>init + e0 + e1 +
3708
+ # e2</code>.
3709
+ #
3710
+ # Examples:
3711
+ #
3712
+ # [0, 1, 2, 3].sum # => 6
3713
+ # [0, 1, 2, 3].sum(100) # => 106
3714
+ # ['abc', 'def', 'ghi'].sum('jkl') # => "jklabcdefghi"
3715
+ # [[:foo, :bar], ['foo', 'bar']].sum([2, 3])
3716
+ # # => [2, 3, :foo, :bar, "foo", "bar"]
3717
+ #
3718
+ # The `init` value and elements need not be numeric, but must all be
3719
+ # <code>+</code>-compatible:
3720
+ #
3721
+ # # Raises TypeError: Array can't be coerced into Integer.
3722
+ # [[:foo, :bar], ['foo', 'bar']].sum(2)
3723
+ #
3724
+ # With a block given, calls the block with each element of `self`; the block's
3725
+ # return value (instead of the element itself) is used as the addend:
3726
+ #
3727
+ # ['zero', 1, :two].sum('Coerced and concatenated: ') {|element| element.to_s }
3728
+ # # => "Coerced and concatenated: zero1two"
3729
+ #
3730
+ # Notes:
3731
+ #
3732
+ # * Array#join and Array#flatten may be faster than Array#sum for an array of
3733
+ # strings or an array of arrays.
3734
+ # * Array#sum method may not respect method redefinition of "+" methods such
3735
+ # as Integer#+.
3736
+ #
3737
+ def sum: (?untyped init) ?{ (E e) -> untyped } -> untyped # This would be usable if we had `where E < Complex`, etc
3738
+
3739
+ # <!--
3740
+ # rdoc-file=array.c
3741
+ # - take(count) -> new_array
3742
+ # -->
3743
+ # Returns a new array containing the first `count` element of `self` (as
3744
+ # available); `count` must be a non-negative numeric; does not modify `self`:
3745
+ #
3746
+ # a = ['a', 'b', 'c', 'd']
3747
+ # a.take(2) # => ["a", "b"]
3748
+ # a.take(2.1) # => ["a", "b"]
3749
+ # a.take(50) # => ["a", "b", "c", "d"]
3750
+ # a.take(0) # => []
3751
+ #
3752
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3753
+ #
3754
+ def take: (int count) -> Array[E]
3755
+
3756
+ # <!--
3757
+ # rdoc-file=array.c
3758
+ # - take_while {|element| ... } -> new_array
3759
+ # - take_while -> new_enumerator
3760
+ # -->
3761
+ # With a block given, calls the block with each successive element of `self`;
3762
+ # stops iterating if the block returns `false` or `nil`; returns a new array
3763
+ # containing those elements for which the block returned a truthy value:
3764
+ #
3765
+ # a = [0, 1, 2, 3, 4, 5]
3766
+ # a.take_while {|element| element < 3 } # => [0, 1, 2]
3767
+ # a.take_while {|element| true } # => [0, 1, 2, 3, 4, 5]
3768
+ # a.take_while {|element| false } # => []
3769
+ #
3770
+ # With no block given, returns a new Enumerator.
3771
+ #
3772
+ # Does not modify `self`.
3773
+ #
3774
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3775
+ #
3776
+ def take_while: () { (E element) -> boolish } -> Array[E]
3777
+ | () -> Enumerator[E, Array[E]]
3778
+
3779
+ # <!--
3780
+ # rdoc-file=array.c
3781
+ # - to_a -> self or new_array
3782
+ # -->
3783
+ # When `self` is an instance of Array, returns `self`.
3784
+ #
3785
+ # Otherwise, returns a new array containing the elements of `self`:
3786
+ #
3787
+ # class MyArray < Array; end
3788
+ # my_a = MyArray.new(['foo', 'bar', 'two'])
3789
+ # a = my_a.to_a
3790
+ # a # => ["foo", "bar", "two"]
3791
+ # a.class # => Array # Not MyArray.
3792
+ #
3793
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
3794
+ #
3795
+ def to_a: () -> Array[E]
3796
+
3797
+ # <!--
3798
+ # rdoc-file=array.c
3799
+ # - to_ary -> self
3800
+ # -->
3801
+ # Returns `self`.
3802
+ #
3803
+ def to_ary: () -> self
3804
+
3805
+ # <!--
3806
+ # rdoc-file=array.c
3807
+ # - to_h -> new_hash
3808
+ # - to_h {|element| ... } -> new_hash
3809
+ # -->
3810
+ # Returns a new hash formed from `self`.
3811
+ #
3812
+ # With no block given, each element of `self` must be a 2-element sub-array;
3813
+ # forms each sub-array into a key-value pair in the new hash:
3814
+ #
3815
+ # a = [['foo', 'zero'], ['bar', 'one'], ['baz', 'two']]
3816
+ # a.to_h # => {"foo"=>"zero", "bar"=>"one", "baz"=>"two"}
3817
+ # [].to_h # => {}
3818
+ #
3819
+ # With a block given, the block must return a 2-element array; calls the block
3820
+ # with each element of `self`; forms each returned array into a key-value pair
3821
+ # in the returned hash:
3822
+ #
3823
+ # a = ['foo', :bar, 1, [2, 3], {baz: 4}]
3824
+ # a.to_h {|element| [element, element.class] }
3825
+ # # => {"foo"=>String, :bar=>Symbol, 1=>Integer, [2, 3]=>Array, {:baz=>4}=>Hash}
3826
+ #
3827
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
3828
+ #
3829
+ def to_h: () -> Hash[untyped, untyped]
3830
+ | [K, V] () { (E element) -> Hash::_Pair[K, V] } -> Hash[K, V]
3831
+
3832
+ # <!-- rdoc-file=array.c -->
3833
+ # Returns the new string formed by calling method <code>#inspect</code> on each
3834
+ # array element:
3835
+ #
3836
+ # a = [:foo, 'bar', 2]
3837
+ # a.inspect # => "[:foo, \"bar\", 2]"
3838
+ #
3839
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
3840
+ #
3841
+ alias to_s inspect
3842
+
3843
+ # <!--
3844
+ # rdoc-file=array.c
3845
+ # - transpose -> new_array
3846
+ # -->
3847
+ # Returns a new array that is `self` as a [transposed
3848
+ # matrix](https://en.wikipedia.org/wiki/Transpose):
3849
+ #
3850
+ # a = [[:a0, :a1], [:b0, :b1], [:c0, :c1]]
3851
+ # a.transpose # => [[:a0, :b0, :c0], [:a1, :b1, :c1]]
3852
+ #
3853
+ # The elements of `self` must all be the same size.
3854
+ #
3855
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
3856
+ #
3857
+ def transpose: () -> Array[Array[untyped]]
3858
+
3859
+ # <!--
3860
+ # rdoc-file=array.c
3861
+ # - union(*other_arrays) -> new_array
3862
+ # -->
3863
+ # Returns a new array that is the union of the elements of `self` and all given
3864
+ # arrays `other_arrays`; items are compared using <code>eql?</code>:
3865
+ #
3866
+ # [0, 1, 2, 3].union([4, 5], [6, 7]) # => [0, 1, 2, 3, 4, 5, 6, 7]
3867
+ #
3868
+ # Removes duplicates (preserving the first found):
3869
+ #
3870
+ # [0, 1, 1].union([2, 1], [3, 1]) # => [0, 1, 2, 3]
3871
+ #
3872
+ # Preserves order (preserving the position of the first found):
3873
+ #
3874
+ # [3, 2, 1, 0].union([5, 3], [4, 2]) # => [3, 2, 1, 0, 5, 4]
3875
+ #
3876
+ # With no arguments given, returns a copy of `self`.
3877
+ #
3878
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
3879
+ #
3880
+ def union: [T] (*array[T] other_arrays) -> Array[T | E] # where E: _Eql?[T]
3881
+
3882
+ # <!--
3883
+ # rdoc-file=array.c
3884
+ # - uniq -> new_array
3885
+ # - uniq {|element| ... } -> new_array
3886
+ # -->
3887
+ # Returns a new array containing those elements from `self` that are not
3888
+ # duplicates, the first occurrence always being retained.
3889
+ #
3890
+ # With no block given, identifies and omits duplicate elements using method
3891
+ # <code>eql?</code> to compare elements:
3892
+ #
3893
+ # a = [0, 0, 1, 1, 2, 2]
3894
+ # a.uniq # => [0, 1, 2]
3895
+ #
3896
+ # With a block given, calls the block for each element; identifies and omits
3897
+ # "duplicate" elements using method <code>eql?</code> to compare *block return
3898
+ # values*; that is, an element is a duplicate if its block return value is the
3899
+ # same as that of a previous element:
3900
+ #
3901
+ # a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
3902
+ # a.uniq {|element| element.size } # => ["a", "aa", "aaa"]
3903
+ #
3904
+ # Related: [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
3905
+ #
3906
+ def uniq: () -> Array[E] # where E: Hash::_Key
3907
+ | () { (E element) -> Hash::_Key } -> Array[E]
3908
+
3909
+ # <!--
3910
+ # rdoc-file=array.c
3911
+ # - uniq! -> self or nil
3912
+ # - uniq! {|element| ... } -> self or nil
3913
+ # -->
3914
+ # Removes duplicate elements from `self`, the first occurrence always being
3915
+ # retained; returns `self` if any elements removed, `nil` otherwise.
3916
+ #
3917
+ # With no block given, identifies and removes elements using method
3918
+ # <code>eql?</code> to compare elements:
3919
+ #
3920
+ # a = [0, 0, 1, 1, 2, 2]
3921
+ # a.uniq! # => [0, 1, 2]
3922
+ # a.uniq! # => nil
3923
+ #
3924
+ # With a block given, calls the block for each element; identifies and omits
3925
+ # "duplicate" elements using method <code>eql?</code> to compare *block return
3926
+ # values*; that is, an element is a duplicate if its block return value is the
3927
+ # same as that of a previous element:
3928
+ #
3929
+ # a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
3930
+ # a.uniq! {|element| element.size } # => ["a", "aa", "aaa"]
3931
+ # a.uniq! {|element| element.size } # => nil
3932
+ #
3933
+ # Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
3934
+ #
3935
+ def uniq!: () -> self? # where E: Hash::_Key
3936
+ | () { (E element) -> Hash::_Key } -> self?
3937
+
3938
+ # <!--
3939
+ # rdoc-file=array.c
3940
+ # - unshift(*objects) -> self
3941
+ # - prepend(*objects) -> self
3942
+ # -->
3943
+ # Prepends the given `objects` to `self`:
3944
+ #
3945
+ # a = [:foo, 'bar', 2]
3946
+ # a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]
3947
+ #
3948
+ # Related: Array#shift; see also [Methods for
3949
+ # Assigning](rdoc-ref:Array@Methods+for+Assigning).
3950
+ #
3951
+ def unshift: (*E objects) -> self
3952
+
3953
+ # <!--
3954
+ # rdoc-file=array.c
3955
+ # - values_at(*specifiers) -> new_array
3956
+ # -->
3957
+ # Returns elements from `self` in a new array; does not modify `self`.
3958
+ #
3959
+ # The objects included in the returned array are the elements of `self` selected
3960
+ # by the given `specifiers`, each of which must be a numeric index or a Range.
3961
+ #
3962
+ # In brief:
3963
+ #
3964
+ # a = ['a', 'b', 'c', 'd']
3965
+ #
3966
+ # # Index specifiers.
3967
+ # a.values_at(2, 0, 2, 0) # => ["c", "a", "c", "a"] # May repeat.
3968
+ # a.values_at(-4, -3, -2, -1) # => ["a", "b", "c", "d"] # Counts backwards if negative.
3969
+ # a.values_at(-50, 50) # => [nil, nil] # Outside of self.
3970
+ #
3971
+ # # Range specifiers.
3972
+ # a.values_at(1..3) # => ["b", "c", "d"] # From range.begin to range.end.
3973
+ # a.values_at(1...3) # => ["b", "c"] # End excluded.
3974
+ # a.values_at(3..1) # => [] # No such elements.
3975
+ #
3976
+ # a.values_at(-3..3) # => ["b", "c", "d"] # Negative range.begin counts backwards.
3977
+ # a.values_at(-50..3) # Raises RangeError.
3978
+ #
3979
+ # a.values_at(1..-2) # => ["b", "c"] # Negative range.end counts backwards.
3980
+ # a.values_at(1..-50) # => [] # No such elements.
3981
+ #
3982
+ # # Mixture of specifiers.
3983
+ # a.values_at(2..3, 3, 0..1, 0) # => ["c", "d", "d", "a", "b", "a"]
3984
+ #
3985
+ # With no `specifiers` given, returns a new empty array:
3986
+ #
3987
+ # a = ['a', 'b', 'c', 'd']
3988
+ # a.values_at # => []
3989
+ #
3990
+ # For each numeric specifier `index`, includes an element:
3991
+ #
3992
+ # * For each non-negative numeric specifier `index` that is in-range (less
3993
+ # than <code>self.size</code>), includes the element at offset `index`:
3994
+ #
3995
+ # a.values_at(0, 2) # => ["a", "c"]
3996
+ # a.values_at(0.1, 2.9) # => ["a", "c"]
3997
+ #
3998
+ # * For each negative numeric `index` that is in-range (greater than or equal
3999
+ # to <code>- self.size</code>), counts backwards from the end of `self`:
4000
+ #
4001
+ # a.values_at(-1, -4) # => ["d", "a"]
4002
+ #
4003
+ # The given indexes may be in any order, and may repeat:
4004
+ #
4005
+ # a.values_at(2, 0, 1, 0, 2) # => ["c", "a", "b", "a", "c"]
4006
+ #
4007
+ # For each `index` that is out-of-range, includes `nil`:
4008
+ #
4009
+ # a.values_at(4, -5) # => [nil, nil]
4010
+ #
4011
+ # For each Range specifier `range`, includes elements according to
4012
+ # <code>range.begin</code> and <code>range.end</code>:
4013
+ #
4014
+ # * If both <code>range.begin</code> and <code>range.end</code> are
4015
+ # non-negative and in-range (less than <code>self.size</code>), includes
4016
+ # elements from index <code>range.begin</code> through <code>range.end -
4017
+ # 1</code> (if <code>range.exclude_end?</code>), or through
4018
+ # <code>range.end</code> (otherwise):
4019
+ #
4020
+ # a.values_at(1..2) # => ["b", "c"]
4021
+ # a.values_at(1...2) # => ["b"]
4022
+ #
4023
+ # * If <code>range.begin</code> is negative and in-range (greater than or
4024
+ # equal to <code>- self.size</code>), counts backwards from the end of
4025
+ # `self`:
4026
+ #
4027
+ # a.values_at(-2..3) # => ["c", "d"]
4028
+ #
4029
+ # * If <code>range.begin</code> is negative and out-of-range, raises an
4030
+ # exception:
4031
+ #
4032
+ # a.values_at(-5..3) # Raises RangeError.
4033
+ #
4034
+ # * If <code>range.end</code> is positive and out-of-range, extends the
4035
+ # returned array with `nil` elements:
4036
+ #
4037
+ # a.values_at(1..5) # => ["b", "c", "d", nil, nil]
4038
+ #
4039
+ # * If <code>range.end</code> is negative and in-range, counts backwards from
4040
+ # the end of `self`:
4041
+ #
4042
+ # a.values_at(1..-2) # => ["b", "c"]
4043
+ #
4044
+ # * If <code>range.end</code> is negative and out-of-range, returns an empty
4045
+ # array:
4046
+ #
4047
+ # a.values_at(1..-5) # => []
4048
+ #
4049
+ # The given ranges may be in any order and may repeat:
4050
+ #
4051
+ # a.values_at(2..3, 0..1, 2..3) # => ["c", "d", "a", "b", "c", "d"]
4052
+ #
4053
+ # The given specifiers may be any mixture of indexes and ranges:
4054
+ #
4055
+ # a.values_at(3, 1..2, 0, 2..3) # => ["d", "b", "c", "a", "c", "d"]
4056
+ #
4057
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
4058
+ #
4059
+ def values_at: (*int | range[int?] selector) -> Array[E?]
4060
+
4061
+ # <!--
4062
+ # rdoc-file=array.c
4063
+ # - zip(*other_arrays) -> new_array
4064
+ # - zip(*other_arrays) {|sub_array| ... } -> nil
4065
+ # -->
4066
+ # With no block given, combines `self` with the collection of `other_arrays`;
4067
+ # returns a new array of sub-arrays:
4068
+ #
4069
+ # [0, 1].zip(['zero', 'one'], [:zero, :one])
4070
+ # # => [[0, "zero", :zero], [1, "one", :one]]
4071
+ #
4072
+ # Returned:
4073
+ #
4074
+ # * The outer array is of size <code>self.size</code>.
4075
+ # * Each sub-array is of size <code>other_arrays.size + 1</code>.
4076
+ # * The *nth* sub-array contains (in order):
4077
+ #
4078
+ # * The *nth* element of `self`.
4079
+ # * The *nth* element of each of the other arrays, as available.
4080
+ #
4081
+ # Example:
4082
+ #
4083
+ # a = [0, 1]
4084
+ # zipped = a.zip(['zero', 'one'], [:zero, :one])
4085
+ # # => [[0, "zero", :zero], [1, "one", :one]]
4086
+ # zipped.size # => 2 # Same size as a.
4087
+ # zipped.first.size # => 3 # Size of other arrays plus 1.
4088
+ #
4089
+ # When the other arrays are all the same size as `self`, the returned sub-arrays
4090
+ # are a rearrangement containing exactly elements of all the arrays (including
4091
+ # `self`), with no omissions or additions:
4092
+ #
4093
+ # a = [:a0, :a1, :a2, :a3]
4094
+ # b = [:b0, :b1, :b2, :b3]
4095
+ # c = [:c0, :c1, :c2, :c3]
4096
+ # d = a.zip(b, c)
4097
+ # pp d
4098
+ # # =>
4099
+ # [[:a0, :b0, :c0],
4100
+ # [:a1, :b1, :c1],
4101
+ # [:a2, :b2, :c2],
4102
+ # [:a3, :b3, :c3]]
4103
+ #
4104
+ # When one of the other arrays is smaller than `self`, pads the corresponding
4105
+ # sub-array with `nil` elements:
4106
+ #
4107
+ # a = [:a0, :a1, :a2, :a3]
4108
+ # b = [:b0, :b1, :b2]
4109
+ # c = [:c0, :c1]
4110
+ # d = a.zip(b, c)
4111
+ # pp d
4112
+ # # =>
4113
+ # [[:a0, :b0, :c0],
4114
+ # [:a1, :b1, :c1],
4115
+ # [:a2, :b2, nil],
4116
+ # [:a3, nil, nil]]
4117
+ #
4118
+ # When one of the other arrays is larger than `self`, *ignores* its trailing
4119
+ # elements:
4120
+ #
4121
+ # a = [:a0, :a1, :a2, :a3]
4122
+ # b = [:b0, :b1, :b2, :b3, :b4]
4123
+ # c = [:c0, :c1, :c2, :c3, :c4, :c5]
4124
+ # d = a.zip(b, c)
4125
+ # pp d
4126
+ # # =>
4127
+ # [[:a0, :b0, :c0],
4128
+ # [:a1, :b1, :c1],
4129
+ # [:a2, :b2, :c2],
4130
+ # [:a3, :b3, :c3]]
4131
+ #
4132
+ # With a block given, calls the block with each of the other arrays; returns
4133
+ # `nil`:
4134
+ #
4135
+ # d = []
4136
+ # a = [:a0, :a1, :a2, :a3]
4137
+ # b = [:b0, :b1, :b2, :b3]
4138
+ # c = [:c0, :c1, :c2, :c3]
4139
+ # a.zip(b, c) {|sub_array| d.push(sub_array.reverse) } # => nil
4140
+ # pp d
4141
+ # # =>
4142
+ # [[:c0, :b0, :a0],
4143
+ # [:c1, :b1, :a1],
4144
+ # [:c2, :b2, :a2],
4145
+ # [:c3, :b3, :a3]]
4146
+ #
4147
+ # For an **object** in **other_arrays** that is not actually an array, forms the
4148
+ # "other array" as <code>object.to_ary</code>, if defined, or as
4149
+ # <code>object.each.to_a</code> otherwise.
4150
+ #
4151
+ # Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
4152
+ #
4153
+ def zip: () -> Array[[ E ]]
4154
+ | [X] (_Each[X] iterable) -> Array[[ E, X? ]]
4155
+ | [X, Y] (_Each[X] iterable1, _Each[Y] iterable2) -> Array[[ E, X?, Y? ]]
4156
+ | [U] (*_Each[U] iterables) -> Array[Array[E | U?]]
4157
+ | () { ([ E ]) -> void } -> nil
4158
+ | [X] (_Each[X] iterable) { ([ E, X? ]) -> void } -> nil
4159
+ | [X, Y] (_Each[X] iterable1, _Each[Y] iterable2) { ([ E, X?, Y? ]) -> void } -> nil
4160
+ | [U] (*_Each[U] iterables) { (Array[E | U?]) -> void } -> nil
4161
+
4162
+ # <!--
4163
+ # rdoc-file=array.c
4164
+ # - self | other_array -> new_array
4165
+ # -->
4166
+ # Returns the union of `self` and `other_array`; duplicates are removed; order
4167
+ # is preserved; items are compared using <code>eql?</code>:
4168
+ #
4169
+ # [0, 1] | [2, 3] # => [0, 1, 2, 3]
4170
+ # [0, 1, 1] | [2, 2, 3] # => [0, 1, 2, 3]
4171
+ # [0, 1, 2] | [3, 2, 1, 0] # => [0, 1, 2, 3]
4172
+ #
4173
+ # Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
4174
+ #
4175
+ def |: [T] (array[T] other_array) -> Array[E | T] # where E: _Eql?[T]
4176
+
4177
+ private
4178
+
4179
+ # <!--
4180
+ # rdoc-file=array.c
4181
+ # - initialize_copy(other_array) -> self
4182
+ # - replace(other_array) -> self
4183
+ # -->
4184
+ # Replaces the elements of `self` with the elements of `other_array`, which must
4185
+ # be an [array-convertible
4186
+ # object](rdoc-ref:implicit_conversion.rdoc@Array-Convertible+Objects); returns
4187
+ # `self`:
4188
+ #
4189
+ # a = ['a', 'b', 'c'] # => ["a", "b", "c"]
4190
+ # a.replace(['d', 'e']) # => ["d", "e"]
4191
+ #
4192
+ # Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
4193
+ #
4194
+ alias initialize_copy replace
4195
+ end
4196
+
4197
+ %a{deprecated: Use Array::_Rand, or make your own}
4198
+ interface _Rand
4199
+ def rand: (Integer max) -> Integer
4200
+ end
4201
+
4202
+ %a{deprecated: Use RBS::Ops::_CaseEqual[E, boolish]}
4203
+ interface Array::_Pattern[T]
4204
+ def ===: (T) -> bool
4205
+ end