rbs 4.1.0.pre.2-java

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