rbs 3.9.4 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.clang-format +75 -0
- data/.clangd +2 -0
- data/.dockerignore +37 -0
- data/.github/dependabot.yml +16 -14
- data/.github/workflows/bundle-update.yml +63 -0
- data/.github/workflows/c-check.yml +66 -0
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/jruby.yml +79 -0
- data/.github/workflows/release-gems.yml +164 -0
- data/.github/workflows/ruby.yml +84 -30
- data/.github/workflows/rust.yml +186 -0
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +5 -2
- data/.github/workflows/wasm.yml +55 -0
- data/.github/workflows/windows.yml +9 -3
- data/.gitignore +16 -0
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +430 -0
- data/Dockerfile.jruby +53 -0
- data/README.md +41 -4
- data/Rakefile +777 -60
- data/Steepfile +11 -0
- data/config.yml +660 -62
- data/core/array.rbs +541 -398
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +9 -8
- data/core/class.rbs +11 -8
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +297 -196
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator/product.rbs +5 -5
- data/core/enumerator.rbs +91 -28
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +260 -1151
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -116
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1151 -829
- data/core/integer.rbs +156 -195
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +220 -154
- data/core/kernel.rbs +239 -163
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +16 -14
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +302 -150
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +77 -63
- data/core/object.rbs +9 -11
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1312 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +364 -518
- data/core/random.rbs +21 -3
- data/core/range.rbs +181 -79
- data/core/rational.rbs +60 -89
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +63 -56
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +78 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +6 -70
- data/core/rubygems/requirement.rbs +5 -15
- data/core/rubygems/rubygems.rbs +18 -81
- data/core/rubygems/specification.rbs +8 -0
- data/core/rubygems/version.rbs +2 -163
- data/core/set.rbs +493 -363
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +43 -42
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +139 -83
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +634 -0
- data/docs/rbs_by_example.md +20 -20
- data/docs/release.md +151 -0
- data/docs/rust.md +96 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +48 -18
- data/docs/type_fingerprint.md +21 -0
- data/docs/wasm_serialization.md +80 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +1855 -0
- data/ext/rbs_extension/ast_translation.h +41 -0
- data/ext/rbs_extension/class_constants.c +187 -0
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +23 -1
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +26 -1
- data/ext/rbs_extension/legacy_location.c +299 -0
- data/ext/rbs_extension/legacy_location.h +82 -0
- data/ext/rbs_extension/main.c +603 -23
- data/ext/rbs_extension/rbs_extension.h +6 -21
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +24 -0
- data/include/rbs/ast.h +1047 -0
- data/include/rbs/defines.h +99 -0
- data/include/rbs/lexer.h +207 -0
- data/include/rbs/location.h +40 -0
- data/include/rbs/parser.h +153 -0
- data/include/rbs/serialize.h +39 -0
- data/include/rbs/string.h +47 -0
- data/include/rbs/util/rbs_allocator.h +59 -0
- data/include/rbs/util/rbs_assert.h +20 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +6 -70
- data/include/rbs/util/rbs_encoding.h +282 -0
- data/include/rbs/util/rbs_unescape.h +24 -0
- data/include/rbs.h +9 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +30 -32
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +451 -0
- data/lib/rbs/ast/ruby/comment_block.rb +247 -0
- data/lib/rbs/ast/ruby/declarations.rb +291 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +762 -0
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +142 -20
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +63 -126
- data/lib/rbs/cli.rb +59 -29
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -3
- data/lib/rbs/collection/sources/git.rb +7 -0
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +121 -65
- data/lib/rbs/definition_builder/method_builder.rb +74 -33
- data/lib/rbs/definition_builder.rb +177 -20
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +410 -215
- data/lib/rbs/environment_loader.rb +2 -8
- data/lib/rbs/errors.rb +31 -21
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +568 -0
- data/lib/rbs/location_aux.rb +36 -4
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +47 -18
- data/lib/rbs/parser_aux.rb +37 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +196 -45
- data/lib/rbs/prototype/runtime.rb +12 -2
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +120 -44
- data/lib/rbs/rewriter.rb +70 -0
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +7 -4
- data/lib/rbs/test/type_check.rb +25 -3
- data/lib/rbs/type_name.rb +34 -21
- data/lib/rbs/types.rb +91 -79
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/unit_test/type_assertions.rb +44 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/runtime.rb +196 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +25 -2
- data/lib/rbs_jars.rb +39 -0
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +8 -3
- data/rbs.gemspec +37 -5
- data/schema/typeParam.json +17 -1
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +13 -10
- data/sig/ast/ruby/annotations.rbs +470 -0
- data/sig/ast/ruby/comment_block.rbs +127 -0
- data/sig/ast/ruby/declarations.rbs +158 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +198 -0
- data/sig/buffer.rbs +81 -5
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/collection/config/lockfile_generator.rbs +2 -0
- data/sig/definition.rbs +6 -0
- data/sig/definition_builder.rbs +3 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +94 -87
- data/sig/errors.rbs +26 -20
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +126 -0
- data/sig/location.rbs +32 -7
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -2
- data/sig/method_builder.rbs +9 -4
- data/sig/namespace.rbs +20 -5
- data/sig/parser.rbs +77 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/prototype/rbi.rbs +33 -4
- data/sig/resolver/type_name_resolver.rbs +36 -10
- data/sig/rewriter.rbs +45 -0
- data/sig/source.rbs +48 -0
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +15 -5
- data/sig/types.rbs +10 -8
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +15 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/src/ast.c +1628 -0
- data/src/lexer.c +3221 -0
- data/src/lexer.re +155 -0
- data/src/lexstate.c +221 -0
- data/src/location.c +31 -0
- data/src/parser.c +4258 -0
- data/src/serialize.c +958 -0
- data/src/string.c +41 -0
- data/src/util/rbs_allocator.c +171 -0
- data/src/util/rbs_assert.c +19 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +18 -92
- data/src/util/rbs_encoding.c +21308 -0
- data/src/util/rbs_unescape.c +167 -0
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +11 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +117 -1
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +73 -54
- data/stdlib/fileutils/0/fileutils.rbs +179 -160
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
- data/stdlib/json/0/json.rbs +232 -185
- data/stdlib/monitor/0/monitor.rbs +5 -5
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +521 -397
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +4 -3
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +7 -5
- data/stdlib/rdoc/0/store.rbs +2 -2
- data/stdlib/resolv/0/resolv.rbs +26 -69
- data/stdlib/ripper/0/ripper.rbs +25 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +3 -3
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -9
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1209 -95
- data/stdlib/strscan/0/string_scanner.rbs +101 -80
- data/stdlib/tempfile/0/manifest.yaml +3 -0
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +58 -7
- data/stdlib/tsort/0/cyclic.rbs +4 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +16 -15
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +21 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +8 -8
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/wasm/README.md +60 -0
- data/wasm/rbs_wasm.c +423 -0
- metadata +131 -19
- data/ext/rbs_extension/lexer.c +0 -2728
- data/ext/rbs_extension/lexer.h +0 -179
- data/ext/rbs_extension/lexer.re +0 -147
- data/ext/rbs_extension/lexstate.c +0 -175
- data/ext/rbs_extension/location.c +0 -325
- data/ext/rbs_extension/location.h +0 -85
- data/ext/rbs_extension/parser.c +0 -2982
- data/ext/rbs_extension/parser.h +0 -18
- data/ext/rbs_extension/parserstate.c +0 -411
- data/ext/rbs_extension/parserstate.h +0 -163
- data/ext/rbs_extension/unescape.c +0 -32
- data/include/rbs/ruby_objs.h +0 -72
- data/src/constants.c +0 -153
- data/src/ruby_objs.c +0 -799
data/core/array.rbs
CHANGED
|
@@ -151,8 +151,8 @@
|
|
|
151
151
|
#
|
|
152
152
|
# ## Example Usage
|
|
153
153
|
#
|
|
154
|
-
# In addition to the methods it mixes in through the Enumerable module,
|
|
155
|
-
#
|
|
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
156
|
# manipulating arrays.
|
|
157
157
|
#
|
|
158
158
|
# Some of the more common ones are illustrated below.
|
|
@@ -200,9 +200,9 @@
|
|
|
200
200
|
#
|
|
201
201
|
# arr.drop(3) #=> [4, 5, 6]
|
|
202
202
|
#
|
|
203
|
-
# ## Obtaining Information about an
|
|
203
|
+
# ## Obtaining Information about an Array
|
|
204
204
|
#
|
|
205
|
-
#
|
|
205
|
+
# An array keeps track of its own length at all times. To query an array about
|
|
206
206
|
# the number of elements it contains, use #length, #count or #size.
|
|
207
207
|
#
|
|
208
208
|
# browsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'IE']
|
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
#
|
|
218
218
|
# browsers.include?('Konqueror') #=> false
|
|
219
219
|
#
|
|
220
|
-
# ## Adding Items to
|
|
220
|
+
# ## Adding Items to an Array
|
|
221
221
|
#
|
|
222
222
|
# Items can be added to the end of an array by using either #push or #<<
|
|
223
223
|
#
|
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
# arr.insert(3, 'orange', 'pear', 'grapefruit')
|
|
239
239
|
# #=> [0, 1, 2, "orange", "pear", "grapefruit", "apple", 3, 4, 5, 6]
|
|
240
240
|
#
|
|
241
|
-
# ## Removing Items from an
|
|
241
|
+
# ## Removing Items from an Array
|
|
242
242
|
#
|
|
243
243
|
# The method #pop removes the last element in an array and returns it:
|
|
244
244
|
#
|
|
@@ -277,12 +277,12 @@
|
|
|
277
277
|
# arr = [2, 5, 6, 556, 6, 6, 8, 9, 0, 123, 556]
|
|
278
278
|
# arr.uniq #=> [2, 5, 6, 556, 8, 9, 0, 123]
|
|
279
279
|
#
|
|
280
|
-
# ## Iterating over
|
|
280
|
+
# ## Iterating over an Array
|
|
281
281
|
#
|
|
282
|
-
# Like all classes that include the Enumerable module,
|
|
282
|
+
# Like all classes that include the Enumerable module, class Array has an each
|
|
283
283
|
# method, which defines what elements should be iterated over and how. In case
|
|
284
|
-
# of Array
|
|
285
|
-
#
|
|
284
|
+
# of Array#each, all elements in `self` are yielded to the supplied block in
|
|
285
|
+
# sequence.
|
|
286
286
|
#
|
|
287
287
|
# Note that this operation leaves the array unchanged.
|
|
288
288
|
#
|
|
@@ -307,7 +307,7 @@
|
|
|
307
307
|
# arr.map! {|a| a**2} #=> [1, 4, 9, 16, 25]
|
|
308
308
|
# arr #=> [1, 4, 9, 16, 25]
|
|
309
309
|
#
|
|
310
|
-
# ## Selecting Items from an
|
|
310
|
+
# ## Selecting Items from an Array
|
|
311
311
|
#
|
|
312
312
|
# Elements can be selected from an array according to criteria defined in a
|
|
313
313
|
# block. The selection can happen in a destructive or a non-destructive manner.
|
|
@@ -340,13 +340,13 @@
|
|
|
340
340
|
#
|
|
341
341
|
# ## What's Here
|
|
342
342
|
#
|
|
343
|
-
# First, what's elsewhere. Class
|
|
343
|
+
# First, what's elsewhere. Class Array:
|
|
344
344
|
#
|
|
345
345
|
# * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
|
|
346
346
|
# * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
|
|
347
347
|
# provides dozens of additional methods.
|
|
348
348
|
#
|
|
349
|
-
# Here, class
|
|
349
|
+
# Here, class Array provides methods that are useful for:
|
|
350
350
|
#
|
|
351
351
|
# * [Creating an Array](rdoc-ref:Array@Methods+for+Creating+an+Array)
|
|
352
352
|
# * [Querying](rdoc-ref:Array@Methods+for+Querying)
|
|
@@ -359,7 +359,7 @@
|
|
|
359
359
|
# * [Converting](rdoc-ref:Array@Methods+for+Converting)
|
|
360
360
|
# * [And more....](rdoc-ref:Array@Other+Methods)
|
|
361
361
|
#
|
|
362
|
-
# ### Methods for Creating an
|
|
362
|
+
# ### Methods for Creating an Array
|
|
363
363
|
#
|
|
364
364
|
# * ::[]: Returns a new array populated with given objects.
|
|
365
365
|
# * ::new: Returns a new array.
|
|
@@ -376,10 +376,10 @@
|
|
|
376
376
|
# * #find_index (aliased as #index): Returns the index of the first element
|
|
377
377
|
# that meets a given criterion.
|
|
378
378
|
# * #hash: Returns the integer hash code.
|
|
379
|
-
# * #include?: Returns whether any element
|
|
379
|
+
# * #include?: Returns whether any element <code>==</code> a given object.
|
|
380
380
|
# * #length (aliased as #size): Returns the count of elements.
|
|
381
|
-
# * #none?: Returns whether no element
|
|
382
|
-
# * #one?: Returns whether exactly one element
|
|
381
|
+
# * #none?: Returns whether no element <code>==</code> a given object.
|
|
382
|
+
# * #one?: Returns whether exactly one element <code>==</code> a given object.
|
|
383
383
|
# * #rindex: Returns the index of the last element that meets a given
|
|
384
384
|
# criterion.
|
|
385
385
|
#
|
|
@@ -387,9 +387,9 @@
|
|
|
387
387
|
#
|
|
388
388
|
# * #<=>: Returns -1, 0, or 1, as `self` is less than, equal to, or greater
|
|
389
389
|
# than a given object.
|
|
390
|
-
# * #==: Returns whether each element in `self` is
|
|
391
|
-
# element in a given object.
|
|
392
|
-
# * #eql?: Returns whether each element in `self` is
|
|
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
393
|
# corresponding element in a given object.
|
|
394
394
|
#
|
|
395
395
|
# ### Methods for Fetching
|
|
@@ -399,7 +399,7 @@
|
|
|
399
399
|
# * #[] (aliased as #slice): Returns consecutive elements as determined by a
|
|
400
400
|
# given argument.
|
|
401
401
|
# * #assoc: Returns the first element that is an array whose first element
|
|
402
|
-
#
|
|
402
|
+
# <code>==</code> a given object.
|
|
403
403
|
# * #at: Returns the element at a given offset.
|
|
404
404
|
# * #bsearch: Returns an element selected via a binary search as determined by
|
|
405
405
|
# a given block.
|
|
@@ -414,14 +414,14 @@
|
|
|
414
414
|
# * #fetch_values: Returns elements at given offsets.
|
|
415
415
|
# * #first: Returns one or more leading elements.
|
|
416
416
|
# * #last: Returns one or more trailing elements.
|
|
417
|
-
# * #max: Returns one or more maximum-valued elements, as determined by
|
|
418
|
-
# or a given block.
|
|
419
|
-
# * #min: Returns one or more minimum-valued elements, as determined by
|
|
420
|
-
# or a given block.
|
|
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
421
|
# * #minmax: Returns the minimum-valued and maximum-valued elements, as
|
|
422
|
-
# determined by
|
|
422
|
+
# determined by <code>#<=></code> or a given block.
|
|
423
423
|
# * #rassoc: Returns the first element that is an array whose second element
|
|
424
|
-
#
|
|
424
|
+
# <code>==</code> a given object.
|
|
425
425
|
# * #reject: Returns an array containing elements not rejected by a given
|
|
426
426
|
# block.
|
|
427
427
|
# * #reverse: Returns all elements in reverse order.
|
|
@@ -430,8 +430,8 @@
|
|
|
430
430
|
# * #select (aliased as #filter): Returns an array containing elements
|
|
431
431
|
# selected by a given block.
|
|
432
432
|
# * #shuffle: Returns elements in a random order.
|
|
433
|
-
# * #sort: Returns all elements in an order determined by
|
|
434
|
-
# block.
|
|
433
|
+
# * #sort: Returns all elements in an order determined by <code>#<=></code> or
|
|
434
|
+
# a given block.
|
|
435
435
|
# * #take: Returns leading elements as determined by a given index.
|
|
436
436
|
# * #take_while: Returns leading elements as determined by a given block.
|
|
437
437
|
# * #uniq: Returns an array containing non-duplicate elements.
|
|
@@ -455,8 +455,8 @@
|
|
|
455
455
|
# * #reverse!: Replaces `self` with its elements reversed.
|
|
456
456
|
# * #rotate!: Replaces `self` with its elements rotated.
|
|
457
457
|
# * #shuffle!: Replaces `self` with its elements in random order.
|
|
458
|
-
# * #sort!: Replaces `self` with its elements sorted, as determined by
|
|
459
|
-
# or a given block.
|
|
458
|
+
# * #sort!: Replaces `self` with its elements sorted, as determined by
|
|
459
|
+
# <code>#<=></code> or a given block.
|
|
460
460
|
# * #sort_by!: Replaces `self` with its elements sorted, as determined by a
|
|
461
461
|
# given block.
|
|
462
462
|
# * #unshift (aliased as #prepend): Prepends leading elements.
|
|
@@ -524,7 +524,7 @@
|
|
|
524
524
|
# return-value.
|
|
525
525
|
# * #flatten: Returns an array that is a recursive flattening of `self`.
|
|
526
526
|
# * #inspect (aliased as #to_s): Returns a new String containing the elements.
|
|
527
|
-
# * #join: Returns a
|
|
527
|
+
# * #join: Returns a new String containing the elements joined by the field
|
|
528
528
|
# separator.
|
|
529
529
|
# * #to_a: Returns `self` or a new array containing all elements.
|
|
530
530
|
# * #to_ary: Returns `self`.
|
|
@@ -539,14 +539,21 @@
|
|
|
539
539
|
# * With integer argument `n`, a new array that is the concatenation of
|
|
540
540
|
# `n` copies of `self`.
|
|
541
541
|
# * With string argument `field_separator`, a new string that is
|
|
542
|
-
# equivalent to
|
|
542
|
+
# equivalent to <code>join(field_separator)</code>.
|
|
543
543
|
#
|
|
544
544
|
# * #pack: Packs the elements into a binary sequence.
|
|
545
|
-
# * #sum: Returns a sum of elements according to either
|
|
545
|
+
# * #sum: Returns a sum of elements according to either <code>+</code> or a
|
|
546
|
+
# given block.
|
|
546
547
|
#
|
|
547
548
|
%a{annotate:rdoc:source:from=array.c}
|
|
548
|
-
class Array[unchecked out
|
|
549
|
-
include Enumerable[
|
|
549
|
+
class Array[unchecked out E]
|
|
550
|
+
include Enumerable[E]
|
|
551
|
+
|
|
552
|
+
# Interface for random number generations; used with `Array#shuffle`, `Array#shuffle!`, and `Array#sample`.
|
|
553
|
+
interface _Rand
|
|
554
|
+
# Generate a random number up to, but excluding, `max`
|
|
555
|
+
def rand: (Integer max) -> int
|
|
556
|
+
end
|
|
550
557
|
|
|
551
558
|
# <!--
|
|
552
559
|
# rdoc-file=array.c
|
|
@@ -574,8 +581,8 @@ class Array[unchecked out Elem] < Object
|
|
|
574
581
|
# Array.new(2, 3) # => [3, 3]
|
|
575
582
|
#
|
|
576
583
|
# With a block given, returns an array of the given `size`; calls the block with
|
|
577
|
-
# each `index` in the range
|
|
578
|
-
# returned array is the blocks return value:
|
|
584
|
+
# each `index` in the range <code>(0...size)</code>; the element at that `index`
|
|
585
|
+
# in the returned array is the blocks return value:
|
|
579
586
|
#
|
|
580
587
|
# Array.new(3) {|index| "Element #{index}" } # => ["Element 0", "Element 1", "Element 2"]
|
|
581
588
|
#
|
|
@@ -603,9 +610,9 @@ class Array[unchecked out Elem] < Object
|
|
|
603
610
|
# Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
|
|
604
611
|
#
|
|
605
612
|
def initialize: () -> void
|
|
606
|
-
| (
|
|
607
|
-
| (int size, ?
|
|
608
|
-
| (int size) { (
|
|
613
|
+
| (array[E] array) -> void
|
|
614
|
+
| (int size, ?E default_value) -> void
|
|
615
|
+
| (int size) { (Integer index) -> E } -> void
|
|
609
616
|
|
|
610
617
|
# <!--
|
|
611
618
|
# rdoc-file=array.c
|
|
@@ -620,7 +627,7 @@ class Array[unchecked out Elem] < Object
|
|
|
620
627
|
# Related: see [Methods for Creating an
|
|
621
628
|
# Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
|
|
622
629
|
#
|
|
623
|
-
def self.[]: [U] (*U) ->
|
|
630
|
+
def self.[]: [U] (*U) -> Array[U] # this technically returns a subclass, but `instance(self)` isn't a thing
|
|
624
631
|
|
|
625
632
|
# <!--
|
|
626
633
|
# rdoc-file=array.c
|
|
@@ -630,16 +637,18 @@ class Array[unchecked out Elem] < Object
|
|
|
630
637
|
#
|
|
631
638
|
# If `object` is an array, returns `object`.
|
|
632
639
|
#
|
|
633
|
-
# Otherwise if `object` responds to
|
|
634
|
-
# return value is an array or `nil`, returns
|
|
635
|
-
# TypeError.
|
|
640
|
+
# Otherwise if `object` responds to <code>:to_ary</code>. calls
|
|
641
|
+
# <code>object.to_ary</code>: if the return value is an array or `nil`, returns
|
|
642
|
+
# that value; if not, raises TypeError.
|
|
636
643
|
#
|
|
637
644
|
# Otherwise returns `nil`.
|
|
638
645
|
#
|
|
639
646
|
# Related: see [Methods for Creating an
|
|
640
647
|
# Array](rdoc-ref:Array@Methods+for+Creating+an+Array).
|
|
641
648
|
#
|
|
642
|
-
def self.try_convert: [U] (
|
|
649
|
+
def self.try_convert: [A < Array[U], U] (A array) -> A
|
|
650
|
+
| [U] (array[U] ary) -> Array[U]?
|
|
651
|
+
| (untyped) -> Array[untyped]?
|
|
643
652
|
|
|
644
653
|
# <!--
|
|
645
654
|
# rdoc-file=array.c
|
|
@@ -658,12 +667,12 @@ class Array[unchecked out Elem] < Object
|
|
|
658
667
|
#
|
|
659
668
|
# [0, 1, 2] & [3, 2, 1, 0] # => [0, 1, 2]
|
|
660
669
|
#
|
|
661
|
-
# Identifies common elements using method
|
|
662
|
-
# `self`).
|
|
670
|
+
# Identifies common elements using method <code>#eql?</code> (as defined in each
|
|
671
|
+
# element of `self`).
|
|
663
672
|
#
|
|
664
673
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
665
674
|
#
|
|
666
|
-
def &: (
|
|
675
|
+
def &: (array[untyped] other_array) -> Array[E] # where E: _Eql?[T]
|
|
667
676
|
|
|
668
677
|
# <!--
|
|
669
678
|
# rdoc-file=array.c
|
|
@@ -677,12 +686,12 @@ class Array[unchecked out Elem] < Object
|
|
|
677
686
|
# a * 3 # => ["x", "y", "x", "y", "x", "y"]
|
|
678
687
|
#
|
|
679
688
|
# When string argument `string_separator` is given, equivalent to
|
|
680
|
-
#
|
|
689
|
+
# <code>self.join(string_separator)</code>:
|
|
681
690
|
#
|
|
682
691
|
# [0, [0, 1], {foo: 0}] * ', ' # => "0, 0, 1, {foo: 0}"
|
|
683
692
|
#
|
|
684
|
-
def *: (string
|
|
685
|
-
| (int
|
|
693
|
+
def *: (string string_separator) -> String # where E: _ToS
|
|
694
|
+
| (int n) -> Array[E] # where E: _ToS
|
|
686
695
|
|
|
687
696
|
# <!--
|
|
688
697
|
# rdoc-file=array.c
|
|
@@ -696,7 +705,7 @@ class Array[unchecked out Elem] < Object
|
|
|
696
705
|
#
|
|
697
706
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
698
707
|
#
|
|
699
|
-
def +: [U] (
|
|
708
|
+
def +: [U] (array[U] other_array) -> Array[E | U]
|
|
700
709
|
|
|
701
710
|
# <!--
|
|
702
711
|
# rdoc-file=array.c
|
|
@@ -709,12 +718,12 @@ class Array[unchecked out Elem] < Object
|
|
|
709
718
|
# [0, 1, 1, 2, 1, 1, 3, 1, 1] - [3, 2, 0, :foo] # => [1, 1, 1, 1, 1, 1]
|
|
710
719
|
# [0, 1, 2] - [:foo] # => [0, 1, 2]
|
|
711
720
|
#
|
|
712
|
-
# Element are compared using method
|
|
713
|
-
# `self`).
|
|
721
|
+
# Element are compared using method <code>#eql?</code> (as defined in each
|
|
722
|
+
# element of `self`).
|
|
714
723
|
#
|
|
715
724
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
716
725
|
#
|
|
717
|
-
def -: (
|
|
726
|
+
def -: (array[untyped] other_array) -> Array[E] # where E: _Eql?[T]
|
|
718
727
|
|
|
719
728
|
# <!--
|
|
720
729
|
# rdoc-file=array.c
|
|
@@ -730,7 +739,7 @@ class Array[unchecked out Elem] < Object
|
|
|
730
739
|
#
|
|
731
740
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
732
741
|
#
|
|
733
|
-
def <<: (
|
|
742
|
+
def <<: (E object) -> self
|
|
734
743
|
|
|
735
744
|
# <!--
|
|
736
745
|
# rdoc-file=array.c
|
|
@@ -739,21 +748,22 @@ class Array[unchecked out Elem] < Object
|
|
|
739
748
|
# Returns -1, 0, or 1 as `self` is determined to be less than, equal to, or
|
|
740
749
|
# greater than `other_array`.
|
|
741
750
|
#
|
|
742
|
-
# Iterates over each index `i` in
|
|
751
|
+
# Iterates over each index `i` in <code>(0...self.size)</code>:
|
|
743
752
|
#
|
|
744
|
-
# * Computes
|
|
745
|
-
#
|
|
753
|
+
# * Computes <code>result[i]</code> as <code>self[i] <=>
|
|
754
|
+
# other_array[i]</code>.
|
|
755
|
+
# * Immediately returns 1 if <code>result[i]</code> is 1:
|
|
746
756
|
#
|
|
747
757
|
# [0, 1, 2] <=> [0, 0, 2] # => 1
|
|
748
758
|
#
|
|
749
|
-
# * Immediately returns -1 if
|
|
759
|
+
# * Immediately returns -1 if <code>result[i]</code> is -1:
|
|
750
760
|
#
|
|
751
761
|
# [0, 1, 2] <=> [0, 2, 2] # => -1
|
|
752
762
|
#
|
|
753
|
-
# * Continues if
|
|
763
|
+
# * Continues if <code>result[i]</code> is 0.
|
|
754
764
|
#
|
|
755
|
-
# When every `result` is 0, returns
|
|
756
|
-
# Integer#<=>):
|
|
765
|
+
# When every `result` is 0, returns <code>self.size <=> other_array.size</code>
|
|
766
|
+
# (see Integer#<=>):
|
|
757
767
|
#
|
|
758
768
|
# [0, 1, 2] <=> [0, 1] # => 1
|
|
759
769
|
# [0, 1, 2] <=> [0, 1, 2] # => 0
|
|
@@ -768,7 +778,7 @@ class Array[unchecked out Elem] < Object
|
|
|
768
778
|
#
|
|
769
779
|
# Related: see [Methods for Comparing](rdoc-ref:Array@Methods+for+Comparing).
|
|
770
780
|
#
|
|
771
|
-
def <=>: (untyped) -> ::Integer
|
|
781
|
+
def <=>: (untyped) -> Integer? # Until we can do `where E: RBS::Ops::_Compare`, this is always going to return `Integer?`
|
|
772
782
|
|
|
773
783
|
# <!--
|
|
774
784
|
# rdoc-file=array.c
|
|
@@ -778,7 +788,7 @@ class Array[unchecked out Elem] < Object
|
|
|
778
788
|
#
|
|
779
789
|
# * `self` and `other_array` are the same size.
|
|
780
790
|
# * Their corresponding elements are the same; that is, for each index `i` in
|
|
781
|
-
#
|
|
791
|
+
# <code>(0...self.size)</code>, <code>self[i] == other_array[i]</code>.
|
|
782
792
|
#
|
|
783
793
|
# Examples:
|
|
784
794
|
#
|
|
@@ -788,7 +798,7 @@ class Array[unchecked out Elem] < Object
|
|
|
788
798
|
# [:foo, 'bar', 2] == [:foo, 'bar', 3] # => false # Different elements.
|
|
789
799
|
#
|
|
790
800
|
# This method is different from method Array#eql?, which compares elements using
|
|
791
|
-
#
|
|
801
|
+
# <code>Object#eql?</code>.
|
|
792
802
|
#
|
|
793
803
|
# Related: see [Methods for Comparing](rdoc-ref:Array@Methods+for+Comparing).
|
|
794
804
|
#
|
|
@@ -840,50 +850,52 @@ class Array[unchecked out Elem] < Object
|
|
|
840
850
|
#
|
|
841
851
|
# If `index` is out of range, returns `nil`.
|
|
842
852
|
#
|
|
843
|
-
# When two Integer arguments `start` and `length` are given, returns a new
|
|
844
|
-
#
|
|
845
|
-
# `start`:
|
|
853
|
+
# When two Integer arguments `start` and `length` are given, returns a new array
|
|
854
|
+
# of size `length` containing successive elements beginning at offset `start`:
|
|
846
855
|
#
|
|
847
856
|
# a = [:foo, 'bar', 2]
|
|
848
857
|
# a[0, 2] # => [:foo, "bar"]
|
|
849
858
|
# a[1, 2] # => ["bar", 2]
|
|
850
859
|
#
|
|
851
|
-
# If
|
|
852
|
-
# offset `start` to the end:
|
|
860
|
+
# If <code>start + length</code> is greater than <code>self.length</code>,
|
|
861
|
+
# returns all elements from offset `start` to the end:
|
|
853
862
|
#
|
|
854
863
|
# a = [:foo, 'bar', 2]
|
|
855
864
|
# a[0, 4] # => [:foo, "bar", 2]
|
|
856
865
|
# a[1, 3] # => ["bar", 2]
|
|
857
866
|
# a[2, 2] # => [2]
|
|
858
867
|
#
|
|
859
|
-
# If
|
|
868
|
+
# If <code>start == self.size</code> and <code>length >= 0</code>, returns a new
|
|
869
|
+
# empty array.
|
|
860
870
|
#
|
|
861
871
|
# If `length` is negative, returns `nil`.
|
|
862
872
|
#
|
|
863
|
-
# When a single Range argument `range` is given, treats
|
|
864
|
-
# above and
|
|
873
|
+
# When a single Range argument `range` is given, treats <code>range.min</code>
|
|
874
|
+
# as `start` above and <code>range.size</code> as `length` above:
|
|
865
875
|
#
|
|
866
876
|
# a = [:foo, 'bar', 2]
|
|
867
877
|
# a[0..1] # => [:foo, "bar"]
|
|
868
878
|
# a[1..2] # => ["bar", 2]
|
|
869
879
|
#
|
|
870
|
-
# Special case: If
|
|
880
|
+
# Special case: If <code>range.start == a.size</code>, returns a new empty
|
|
881
|
+
# array.
|
|
871
882
|
#
|
|
872
|
-
# If
|
|
883
|
+
# If <code>range.end</code> is negative, calculates the end index from the end:
|
|
873
884
|
#
|
|
874
885
|
# a = [:foo, 'bar', 2]
|
|
875
886
|
# a[0..-1] # => [:foo, "bar", 2]
|
|
876
887
|
# a[0..-2] # => [:foo, "bar"]
|
|
877
888
|
# a[0..-3] # => [:foo]
|
|
878
889
|
#
|
|
879
|
-
# If
|
|
890
|
+
# If <code>range.start</code> is negative, calculates the start index from the
|
|
891
|
+
# end:
|
|
880
892
|
#
|
|
881
893
|
# a = [:foo, 'bar', 2]
|
|
882
894
|
# a[-1..2] # => [2]
|
|
883
895
|
# a[-2..2] # => ["bar", 2]
|
|
884
896
|
# a[-3..2] # => [:foo, "bar", 2]
|
|
885
897
|
#
|
|
886
|
-
# If
|
|
898
|
+
# If <code>range.start</code> is larger than the array size, returns `nil`.
|
|
887
899
|
#
|
|
888
900
|
# a = [:foo, 'bar', 2]
|
|
889
901
|
# a[4..1] # => nil
|
|
@@ -891,7 +903,7 @@ class Array[unchecked out Elem] < Object
|
|
|
891
903
|
# a[4..-1] # => nil
|
|
892
904
|
#
|
|
893
905
|
# When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
|
|
894
|
-
# an
|
|
906
|
+
# an array of elements corresponding to the indexes produced by the sequence.
|
|
895
907
|
#
|
|
896
908
|
# a = ['--', 'data1', '--', 'data2', '--', 'data3']
|
|
897
909
|
# a[(1..).step(2)] # => ["data1", "data2", "data3"]
|
|
@@ -914,9 +926,9 @@ class Array[unchecked out Elem] < Object
|
|
|
914
926
|
#
|
|
915
927
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
916
928
|
#
|
|
917
|
-
def []: %a{implicitly-returns-nil} (int index) ->
|
|
918
|
-
| (int start, int length) ->
|
|
919
|
-
| (
|
|
929
|
+
def []: %a{implicitly-returns-nil} (int index) -> E
|
|
930
|
+
| (int start, int length) -> Array[E]?
|
|
931
|
+
| (range[int] range) -> Array[E]?
|
|
920
932
|
|
|
921
933
|
# <!--
|
|
922
934
|
# rdoc-file=array.c
|
|
@@ -963,7 +975,7 @@ class Array[unchecked out Elem] < Object
|
|
|
963
975
|
# a[0] = 'foo' # => "foo"
|
|
964
976
|
# a # => ["foo", "bar", 2]
|
|
965
977
|
#
|
|
966
|
-
# If `index` is greater than
|
|
978
|
+
# If `index` is greater than <code>self.length</code>, extends the array:
|
|
967
979
|
#
|
|
968
980
|
# a = [:foo, 'bar', 2]
|
|
969
981
|
# a[7] = 'foo' # => "foo"
|
|
@@ -976,8 +988,8 @@ class Array[unchecked out Elem] < Object
|
|
|
976
988
|
# a # => [:foo, "bar", "two"]
|
|
977
989
|
#
|
|
978
990
|
# When Integer arguments `start` and `length` are given and `object` is not an
|
|
979
|
-
#
|
|
980
|
-
# assigns `object` at offset `start`:
|
|
991
|
+
# array, removes <code>length - 1</code> elements beginning at offset `start`,
|
|
992
|
+
# and assigns `object` at offset `start`:
|
|
981
993
|
#
|
|
982
994
|
# a = [:foo, 'bar', 2]
|
|
983
995
|
# a[0, 2] = 'foo' # => "foo"
|
|
@@ -989,8 +1001,8 @@ class Array[unchecked out Elem] < Object
|
|
|
989
1001
|
# a[-2, 2] = 'foo' # => "foo"
|
|
990
1002
|
# a # => [:foo, "foo"]
|
|
991
1003
|
#
|
|
992
|
-
# If `start` is non-negative and outside the array (
|
|
993
|
-
# the array with `nil`, assigns `object` at offset `start`, and ignores
|
|
1004
|
+
# If `start` is non-negative and outside the array (<code> >= self.size</code>),
|
|
1005
|
+
# extends the array with `nil`, assigns `object` at offset `start`, and ignores
|
|
994
1006
|
# `length`:
|
|
995
1007
|
#
|
|
996
1008
|
# a = [:foo, 'bar', 2]
|
|
@@ -1010,36 +1022,39 @@ class Array[unchecked out Elem] < Object
|
|
|
1010
1022
|
# a[1, 5] = 'foo' # => "foo"
|
|
1011
1023
|
# a # => [:foo, "foo"]
|
|
1012
1024
|
#
|
|
1013
|
-
# When Range argument `range` is given and `object` is not an
|
|
1014
|
-
#
|
|
1015
|
-
# offset `start`:
|
|
1025
|
+
# When Range argument `range` is given and `object` is not an array, removes
|
|
1026
|
+
# <code>length - 1</code> elements beginning at offset `start`, and assigns
|
|
1027
|
+
# `object` at offset `start`:
|
|
1016
1028
|
#
|
|
1017
1029
|
# a = [:foo, 'bar', 2]
|
|
1018
1030
|
# a[0..1] = 'foo' # => "foo"
|
|
1019
1031
|
# a # => ["foo", 2]
|
|
1020
1032
|
#
|
|
1021
|
-
# if
|
|
1033
|
+
# if <code>range.begin</code> is negative, counts backwards from the end of the
|
|
1034
|
+
# array:
|
|
1022
1035
|
#
|
|
1023
1036
|
# a = [:foo, 'bar', 2]
|
|
1024
1037
|
# a[-2..2] = 'foo' # => "foo"
|
|
1025
1038
|
# a # => [:foo, "foo"]
|
|
1026
1039
|
#
|
|
1027
|
-
# If the array length is less than
|
|
1028
|
-
# assigns `object` at offset
|
|
1040
|
+
# If the array length is less than <code>range.begin</code>, extends the array
|
|
1041
|
+
# with `nil`, assigns `object` at offset <code>range.begin</code>, and ignores
|
|
1042
|
+
# `length`:
|
|
1029
1043
|
#
|
|
1030
1044
|
# a = [:foo, 'bar', 2]
|
|
1031
1045
|
# a[6..50] = 'foo' # => "foo"
|
|
1032
1046
|
# a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
|
|
1033
1047
|
#
|
|
1034
|
-
# If
|
|
1035
|
-
# assigns `object` at offset `start`:
|
|
1048
|
+
# If <code>range.end</code> is zero, shifts elements at and following offset
|
|
1049
|
+
# `start` and assigns `object` at offset `start`:
|
|
1036
1050
|
#
|
|
1037
1051
|
# a = [:foo, 'bar', 2]
|
|
1038
1052
|
# a[1..0] = 'foo' # => "foo"
|
|
1039
1053
|
# a # => [:foo, "foo", "bar", 2]
|
|
1040
1054
|
#
|
|
1041
|
-
# If
|
|
1042
|
-
#
|
|
1055
|
+
# If <code>range.end</code> is negative, assigns `object` at offset `start`,
|
|
1056
|
+
# retains <code>range.end.abs -1</code> elements past that, and removes those
|
|
1057
|
+
# beyond:
|
|
1043
1058
|
#
|
|
1044
1059
|
# a = [:foo, 'bar', 2]
|
|
1045
1060
|
# a[1..-1] = 'foo' # => "foo"
|
|
@@ -1052,8 +1067,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1052
1067
|
# a # => [:foo, "foo", "bar", 2]
|
|
1053
1068
|
# a = [:foo, 'bar', 2]
|
|
1054
1069
|
#
|
|
1055
|
-
# If
|
|
1056
|
-
# but does not extend the array with `nil` values:
|
|
1070
|
+
# If <code>range.end</code> is too large for the existing array, replaces array
|
|
1071
|
+
# elements, but does not extend the array with `nil` values:
|
|
1057
1072
|
#
|
|
1058
1073
|
# a = [:foo, 'bar', 2]
|
|
1059
1074
|
# a[1..5] = 'foo' # => "foo"
|
|
@@ -1061,13 +1076,11 @@ class Array[unchecked out Elem] < Object
|
|
|
1061
1076
|
#
|
|
1062
1077
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
1063
1078
|
#
|
|
1064
|
-
def []=: (int index,
|
|
1065
|
-
|
|
|
1066
|
-
| (int
|
|
1067
|
-
| (int start, int length,
|
|
1068
|
-
| (
|
|
1069
|
-
| (::Range[::Integer?], ::Array[Elem]) -> ::Array[Elem]
|
|
1070
|
-
| (::Range[::Integer?], nil) -> nil
|
|
1079
|
+
def []=: (int index, E object) -> E
|
|
1080
|
+
| [T < _ToAry[E]] (range[int?] range, T array) -> T
|
|
1081
|
+
| (range[int?] range, E object) -> E
|
|
1082
|
+
| [T < _ToAry[E]] (int start, int length, T array) -> T
|
|
1083
|
+
| (int start, int length, E object) -> E
|
|
1071
1084
|
|
|
1072
1085
|
# <!--
|
|
1073
1086
|
# rdoc-file=array.c
|
|
@@ -1084,8 +1097,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1084
1097
|
# [[], {}, '', 0, 0.0, nil].all? # => false # nil is not truthy.
|
|
1085
1098
|
# [[], {}, '', 0, 0.0, false].all? # => false # false is not truthy.
|
|
1086
1099
|
#
|
|
1087
|
-
# With argument `object` given, returns whether
|
|
1088
|
-
# element `ele` in `self`:
|
|
1100
|
+
# With argument `object` given, returns whether <code>object === ele</code> for
|
|
1101
|
+
# every element `ele` in `self`:
|
|
1089
1102
|
#
|
|
1090
1103
|
# [0, 0, 0].all?(0) # => true
|
|
1091
1104
|
# [0, 1, 2].all?(1) # => false
|
|
@@ -1107,8 +1120,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1107
1120
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
1108
1121
|
#
|
|
1109
1122
|
def all?: () -> bool
|
|
1110
|
-
| (
|
|
1111
|
-
| () { (
|
|
1123
|
+
| (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
|
|
1124
|
+
| () { (E element) -> boolish } -> bool
|
|
1112
1125
|
|
|
1113
1126
|
# <!--
|
|
1114
1127
|
# rdoc-file=array.c
|
|
@@ -1126,8 +1139,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1126
1139
|
# [nil, false, ''].any? # => true # String object is truthy.
|
|
1127
1140
|
# [nil, false].any? # => false # Nil and false are not truthy.
|
|
1128
1141
|
#
|
|
1129
|
-
# With argument `object` given, returns whether
|
|
1130
|
-
# `ele` in `self`:
|
|
1142
|
+
# With argument `object` given, returns whether <code>object === ele</code> for
|
|
1143
|
+
# any element `ele` in `self`:
|
|
1131
1144
|
#
|
|
1132
1145
|
# [nil, false, 0].any?(0) # => true
|
|
1133
1146
|
# [nil, false, 1].any?(0) # => false
|
|
@@ -1148,7 +1161,9 @@ class Array[unchecked out Elem] < Object
|
|
|
1148
1161
|
#
|
|
1149
1162
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
1150
1163
|
#
|
|
1151
|
-
|
|
1164
|
+
def any?: () -> bool
|
|
1165
|
+
| (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
|
|
1166
|
+
| () { (E element) -> boolish } -> bool
|
|
1152
1167
|
|
|
1153
1168
|
# <!-- rdoc-file=array.c -->
|
|
1154
1169
|
# Appends each argument in `objects` to `self`; returns `self`:
|
|
@@ -1170,7 +1185,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1170
1185
|
# - assoc(object) -> found_array or nil
|
|
1171
1186
|
# -->
|
|
1172
1187
|
# Returns the first element `ele` in `self` such that `ele` is an array and
|
|
1173
|
-
#
|
|
1188
|
+
# <code>ele[0] == object</code>:
|
|
1174
1189
|
#
|
|
1175
1190
|
# a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
|
|
1176
1191
|
# a.assoc(4) # => [4, 5, 6]
|
|
@@ -1180,7 +1195,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1180
1195
|
# Related: Array#rassoc; see also [Methods for
|
|
1181
1196
|
# Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1182
1197
|
#
|
|
1183
|
-
def assoc: (untyped) ->
|
|
1198
|
+
def assoc: (untyped object) -> Array[untyped]? # where E: _ToAry[X], object: _Equal
|
|
1184
1199
|
|
|
1185
1200
|
# <!--
|
|
1186
1201
|
# rdoc-file=array.c
|
|
@@ -1204,7 +1219,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1204
1219
|
# Related: Array#[]; see also [Methods for
|
|
1205
1220
|
# Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1206
1221
|
#
|
|
1207
|
-
def at: %a{implicitly-returns-nil} (int index) ->
|
|
1222
|
+
def at: %a{implicitly-returns-nil} (int index) -> E
|
|
1208
1223
|
|
|
1209
1224
|
# <!--
|
|
1210
1225
|
# rdoc-file=array.c
|
|
@@ -1214,13 +1229,13 @@ class Array[unchecked out Elem] < Object
|
|
|
1214
1229
|
# Returns the element from `self` found by a binary search, or `nil` if the
|
|
1215
1230
|
# search found no suitable element.
|
|
1216
1231
|
#
|
|
1217
|
-
# See [Binary Searching](rdoc-ref:bsearch.rdoc).
|
|
1232
|
+
# See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
|
|
1218
1233
|
#
|
|
1219
1234
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1220
1235
|
#
|
|
1221
|
-
def bsearch: () ->
|
|
1222
|
-
| () { (
|
|
1223
|
-
| ()
|
|
1236
|
+
def bsearch: () { (E element) -> bool? } -> E?
|
|
1237
|
+
| () { (E element) -> Numeric? } -> E?
|
|
1238
|
+
| () -> Enumerator[E, E?]
|
|
1224
1239
|
|
|
1225
1240
|
# <!--
|
|
1226
1241
|
# rdoc-file=array.c
|
|
@@ -1230,12 +1245,13 @@ class Array[unchecked out Elem] < Object
|
|
|
1230
1245
|
# Returns the integer index of the element from `self` found by a binary search,
|
|
1231
1246
|
# or `nil` if the search found no suitable element.
|
|
1232
1247
|
#
|
|
1233
|
-
# See [Binary Searching](rdoc-ref:bsearch.rdoc).
|
|
1248
|
+
# See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
|
|
1234
1249
|
#
|
|
1235
1250
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1236
1251
|
#
|
|
1237
|
-
def bsearch_index: () { (
|
|
1238
|
-
| () { (
|
|
1252
|
+
def bsearch_index: () { (E element) -> bool? } -> Integer?
|
|
1253
|
+
| () { (E element) -> Numeric? } -> Integer?
|
|
1254
|
+
| () -> Enumerator[E, Integer?]
|
|
1239
1255
|
|
|
1240
1256
|
# <!--
|
|
1241
1257
|
# rdoc-file=array.c
|
|
@@ -1269,14 +1285,14 @@ class Array[unchecked out Elem] < Object
|
|
|
1269
1285
|
# Related: #collect!; see also [Methods for
|
|
1270
1286
|
# Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
1271
1287
|
#
|
|
1272
|
-
def collect: [
|
|
1273
|
-
| () ->
|
|
1288
|
+
def collect: [T] () { (E item) -> T } -> Array[T]
|
|
1289
|
+
| () -> Enumerator[E, Array[untyped]]
|
|
1274
1290
|
|
|
1275
1291
|
# <!--
|
|
1276
1292
|
# rdoc-file=array.c
|
|
1277
|
-
# - collect! {|element| ... } ->
|
|
1293
|
+
# - collect! {|element| ... } -> self
|
|
1278
1294
|
# - collect! -> new_enumerator
|
|
1279
|
-
# - map! {|element| ... } ->
|
|
1295
|
+
# - map! {|element| ... } -> self
|
|
1280
1296
|
# - map! -> new_enumerator
|
|
1281
1297
|
# -->
|
|
1282
1298
|
# With a block given, calls the block with each element of `self` and replaces
|
|
@@ -1290,8 +1306,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1290
1306
|
# Related: #collect; see also [Methods for
|
|
1291
1307
|
# Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
1292
1308
|
#
|
|
1293
|
-
def collect!: () { (
|
|
1294
|
-
| () ->
|
|
1309
|
+
def collect!: () { (E element) -> E } -> self
|
|
1310
|
+
| () -> Enumerator[E, self]
|
|
1295
1311
|
|
|
1296
1312
|
# <!--
|
|
1297
1313
|
# rdoc-file=array.c
|
|
@@ -1300,8 +1316,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1300
1316
|
# -->
|
|
1301
1317
|
# When a block and a positive [integer-convertible
|
|
1302
1318
|
# object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects)
|
|
1303
|
-
# argument `count` (
|
|
1304
|
-
# each combination of `self` of size `count`; returns `self`:
|
|
1319
|
+
# argument `count` (<code>0 < count <= self.size</code>) are given, calls the
|
|
1320
|
+
# block with each combination of `self` of size `count`; returns `self`:
|
|
1305
1321
|
#
|
|
1306
1322
|
# a = %w[a b c] # => ["a", "b", "c"]
|
|
1307
1323
|
# a.combination(2) {|combination| p combination } # => ["a", "b", "c"]
|
|
@@ -1324,8 +1340,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1324
1340
|
# []
|
|
1325
1341
|
# []
|
|
1326
1342
|
#
|
|
1327
|
-
# When `count` is negative or larger than
|
|
1328
|
-
# does not call the block:
|
|
1343
|
+
# When `count` is negative or larger than <code>self.size</code> and `self` is
|
|
1344
|
+
# non-empty, does not call the block:
|
|
1329
1345
|
#
|
|
1330
1346
|
# a.combination(-1) {|combination| fail 'Cannot happen' } # => ["a", "b", "c"]
|
|
1331
1347
|
# a.combination(4) {|combination| fail 'Cannot happen' } # => ["a", "b", "c"]
|
|
@@ -1335,8 +1351,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1335
1351
|
# Related: Array#permutation; see also [Methods for
|
|
1336
1352
|
# Iterating](rdoc-ref:Array@Methods+for+Iterating).
|
|
1337
1353
|
#
|
|
1338
|
-
def combination: (int
|
|
1339
|
-
| (int
|
|
1354
|
+
def combination: (int count) { (Array[E] combination) -> void } -> self
|
|
1355
|
+
| (int count) -> Enumerator[Array[E], self]
|
|
1340
1356
|
|
|
1341
1357
|
# <!--
|
|
1342
1358
|
# rdoc-file=array.c
|
|
@@ -1351,7 +1367,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1351
1367
|
# Related: Array#compact!; see also [Methods for
|
|
1352
1368
|
# Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
1353
1369
|
#
|
|
1354
|
-
def compact: () ->
|
|
1370
|
+
def compact: () -> Array[E] # it'd be nice if there was a way to do `Array[E - nil]`
|
|
1355
1371
|
|
|
1356
1372
|
# <!--
|
|
1357
1373
|
# rdoc-file=array.c
|
|
@@ -1382,7 +1398,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1382
1398
|
#
|
|
1383
1399
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
1384
1400
|
#
|
|
1385
|
-
def concat: (
|
|
1401
|
+
def concat: (*array[E] other_arrays) -> self
|
|
1386
1402
|
|
|
1387
1403
|
# <!--
|
|
1388
1404
|
# rdoc-file=array.c
|
|
@@ -1396,7 +1412,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1396
1412
|
#
|
|
1397
1413
|
# [0, :one, 'two', 3, 3.0].count # => 5
|
|
1398
1414
|
#
|
|
1399
|
-
# With argument `object` given, returns the count of elements
|
|
1415
|
+
# With argument `object` given, returns the count of elements <code>==</code> to
|
|
1416
|
+
# `object`:
|
|
1400
1417
|
#
|
|
1401
1418
|
# [0, :one, 'two', 3, 3.0].count(3) # => 2
|
|
1402
1419
|
#
|
|
@@ -1406,13 +1423,12 @@ class Array[unchecked out Elem] < Object
|
|
|
1406
1423
|
# [0, 1, 2, 3].count {|element| element > 1 } # => 2
|
|
1407
1424
|
#
|
|
1408
1425
|
# With argument `object` and a block given, issues a warning, ignores the block,
|
|
1409
|
-
# and returns the count of elements
|
|
1426
|
+
# and returns the count of elements <code>==</code> to `object`.
|
|
1410
1427
|
#
|
|
1411
1428
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
1412
1429
|
#
|
|
1413
|
-
def count: () ->
|
|
1414
|
-
| (
|
|
1415
|
-
| () { (Elem) -> boolish } -> ::Integer
|
|
1430
|
+
def count: () ?{ (E element) -> boolish } -> Integer
|
|
1431
|
+
| (untyped object) -> Integer # where E: RBS::Ops::_Equal
|
|
1416
1432
|
|
|
1417
1433
|
# <!--
|
|
1418
1434
|
# rdoc-file=array.c
|
|
@@ -1446,8 +1462,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1446
1462
|
#
|
|
1447
1463
|
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
|
|
1448
1464
|
#
|
|
1449
|
-
def cycle: (?int? n) { (
|
|
1450
|
-
| (?int? n) ->
|
|
1465
|
+
def cycle: (?int? n) { (E element) -> void } -> nil
|
|
1466
|
+
| (?int? n) -> Enumerator[E, nil]
|
|
1451
1467
|
|
|
1452
1468
|
# <!--
|
|
1453
1469
|
# rdoc-file=array.c
|
|
@@ -1463,8 +1479,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1463
1479
|
# -->
|
|
1464
1480
|
# Removes zero or more elements from `self`.
|
|
1465
1481
|
#
|
|
1466
|
-
# With no block given, removes from `self` each element `ele` such that
|
|
1467
|
-
# object
|
|
1482
|
+
# With no block given, removes from `self` each element `ele` such that
|
|
1483
|
+
# <code>ele == object</code>; returns the last removed element:
|
|
1468
1484
|
#
|
|
1469
1485
|
# a = [0, 1, 2, 2.0]
|
|
1470
1486
|
# a.delete(2) # => 2.0
|
|
@@ -1474,8 +1490,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1474
1490
|
#
|
|
1475
1491
|
# a.delete(2) # => nil
|
|
1476
1492
|
#
|
|
1477
|
-
# With a block given, removes from `self` each element `ele` such that
|
|
1478
|
-
# object
|
|
1493
|
+
# With a block given, removes from `self` each element `ele` such that <code>ele
|
|
1494
|
+
# == object</code>.
|
|
1479
1495
|
#
|
|
1480
1496
|
# If any such elements are found, ignores the block and returns the last removed
|
|
1481
1497
|
# element:
|
|
@@ -1491,8 +1507,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1491
1507
|
#
|
|
1492
1508
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
1493
1509
|
#
|
|
1494
|
-
def delete: (
|
|
1495
|
-
| [S, T] (S
|
|
1510
|
+
def delete: (untyped object) -> E? # where E: _Comparable
|
|
1511
|
+
| [S, T] (S object) { (S object) -> T } -> (E | T)
|
|
1496
1512
|
|
|
1497
1513
|
# <!--
|
|
1498
1514
|
# rdoc-file=array.c
|
|
@@ -1522,7 +1538,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1522
1538
|
#
|
|
1523
1539
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
1524
1540
|
#
|
|
1525
|
-
def delete_at: %a{implicitly-returns-nil} (int index) ->
|
|
1541
|
+
def delete_at: %a{implicitly-returns-nil} (int index) -> E
|
|
1526
1542
|
|
|
1527
1543
|
# <!--
|
|
1528
1544
|
# rdoc-file=array.c
|
|
@@ -1539,16 +1555,33 @@ class Array[unchecked out Elem] < Object
|
|
|
1539
1555
|
#
|
|
1540
1556
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
1541
1557
|
#
|
|
1542
|
-
def delete_if: () { (
|
|
1543
|
-
| () ->
|
|
1558
|
+
def delete_if: () { (E item) -> boolish } -> self
|
|
1559
|
+
| () -> Enumerator[E, self]
|
|
1560
|
+
|
|
1561
|
+
# <!-- rdoc-file=array.c -->
|
|
1562
|
+
# Returns the first element for which the block returns a truthy value.
|
|
1563
|
+
#
|
|
1564
|
+
# With a block given, calls the block with successive elements of the array;
|
|
1565
|
+
# returns the first element for which the block returns a truthy value:
|
|
1566
|
+
#
|
|
1567
|
+
# [1, 3, 5].find {|element| element > 2} # => 3
|
|
1568
|
+
#
|
|
1569
|
+
# If no such element is found, calls `if_none_proc` and returns its return
|
|
1570
|
+
# value.
|
|
1571
|
+
#
|
|
1572
|
+
# [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1
|
|
1573
|
+
#
|
|
1574
|
+
# With no block given, returns an Enumerator.
|
|
1575
|
+
#
|
|
1576
|
+
alias detect find
|
|
1544
1577
|
|
|
1545
1578
|
# <!--
|
|
1546
1579
|
# rdoc-file=array.c
|
|
1547
1580
|
# - difference(*other_arrays = []) -> new_array
|
|
1548
1581
|
# -->
|
|
1549
1582
|
# Returns a new array containing only those elements from `self` that are not
|
|
1550
|
-
# found in any of the given `other_arrays`; items are compared using
|
|
1551
|
-
# order from `self` is preserved:
|
|
1583
|
+
# found in any of the given `other_arrays`; items are compared using
|
|
1584
|
+
# <code>eql?</code>; order from `self` is preserved:
|
|
1552
1585
|
#
|
|
1553
1586
|
# [0, 1, 1, 2, 1, 1, 3, 1, 1].difference([1]) # => [0, 2, 3]
|
|
1554
1587
|
# [0, 1, 2, 3].difference([3, 0], [1, 3]) # => [2]
|
|
@@ -1560,11 +1593,11 @@ class Array[unchecked out Elem] < Object
|
|
|
1560
1593
|
# Related: Array#-; see also [Methods for
|
|
1561
1594
|
# Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
1562
1595
|
#
|
|
1563
|
-
def difference: (
|
|
1596
|
+
def difference: (*array[untyped] other_arrays) -> Array[E]
|
|
1564
1597
|
|
|
1565
1598
|
# <!--
|
|
1566
1599
|
# rdoc-file=array.c
|
|
1567
|
-
# -
|
|
1600
|
+
# - dig(index, *identifiers) -> object
|
|
1568
1601
|
# -->
|
|
1569
1602
|
# Finds and returns the object in nested object specified by `index` and
|
|
1570
1603
|
# `identifiers`; the nested objects may be instances of various classes. See
|
|
@@ -1580,8 +1613,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1580
1613
|
#
|
|
1581
1614
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1582
1615
|
#
|
|
1583
|
-
def dig: (int
|
|
1584
|
-
| (int
|
|
1616
|
+
def dig: (int index) -> E?
|
|
1617
|
+
| (int index, untyped, *untyped) -> untyped
|
|
1585
1618
|
|
|
1586
1619
|
# <!--
|
|
1587
1620
|
# rdoc-file=array.c
|
|
@@ -1600,7 +1633,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1600
1633
|
#
|
|
1601
1634
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1602
1635
|
#
|
|
1603
|
-
def drop: (int
|
|
1636
|
+
def drop: (int count) -> Array[E]
|
|
1604
1637
|
|
|
1605
1638
|
# <!--
|
|
1606
1639
|
# rdoc-file=array.c
|
|
@@ -1619,8 +1652,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1619
1652
|
#
|
|
1620
1653
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1621
1654
|
#
|
|
1622
|
-
def drop_while: () { (
|
|
1623
|
-
| () ->
|
|
1655
|
+
def drop_while: () { (E element) -> boolish } -> Array[E]
|
|
1656
|
+
| () -> Enumerator[E, Array[E]]
|
|
1624
1657
|
|
|
1625
1658
|
# <!--
|
|
1626
1659
|
# rdoc-file=array.c
|
|
@@ -1653,8 +1686,8 @@ class Array[unchecked out Elem] < Object
|
|
|
1653
1686
|
#
|
|
1654
1687
|
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
|
|
1655
1688
|
#
|
|
1656
|
-
def each: () ->
|
|
1657
|
-
| ()
|
|
1689
|
+
def each: () { (E element) -> void } -> self
|
|
1690
|
+
| () -> Enumerator[E, self]
|
|
1658
1691
|
|
|
1659
1692
|
# <!--
|
|
1660
1693
|
# rdoc-file=array.c
|
|
@@ -1688,12 +1721,12 @@ class Array[unchecked out Elem] < Object
|
|
|
1688
1721
|
#
|
|
1689
1722
|
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
|
|
1690
1723
|
#
|
|
1691
|
-
def each_index: () { (
|
|
1692
|
-
| () ->
|
|
1724
|
+
def each_index: () { (Integer index) -> void } -> self
|
|
1725
|
+
| () -> Enumerator[Integer, self]
|
|
1693
1726
|
|
|
1694
1727
|
# <!--
|
|
1695
1728
|
# rdoc-file=array.c
|
|
1696
|
-
# -
|
|
1729
|
+
# - empty? -> true or false
|
|
1697
1730
|
# -->
|
|
1698
1731
|
# Returns `true` if the count of elements in `self` is zero, `false` otherwise.
|
|
1699
1732
|
#
|
|
@@ -1706,7 +1739,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1706
1739
|
# - eql?(other_array) -> true or false
|
|
1707
1740
|
# -->
|
|
1708
1741
|
# Returns `true` if `self` and `other_array` are the same size, and if, for each
|
|
1709
|
-
# index `i` in `self`,
|
|
1742
|
+
# index `i` in `self`, <code>self[i].eql?(other_array[i])</code>:
|
|
1710
1743
|
#
|
|
1711
1744
|
# a0 = [:foo, 'bar', 2]
|
|
1712
1745
|
# a1 = [:foo, 'bar', 2]
|
|
@@ -1715,7 +1748,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1715
1748
|
# Otherwise, returns `false`.
|
|
1716
1749
|
#
|
|
1717
1750
|
# This method is different from method Array#==, which compares using method
|
|
1718
|
-
#
|
|
1751
|
+
# <code>Object#==</code>.
|
|
1719
1752
|
#
|
|
1720
1753
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
1721
1754
|
#
|
|
@@ -1761,9 +1794,9 @@ class Array[unchecked out Elem] < Object
|
|
|
1761
1794
|
#
|
|
1762
1795
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1763
1796
|
#
|
|
1764
|
-
def fetch: (int index) ->
|
|
1765
|
-
| [T] (int index, T default) -> (
|
|
1766
|
-
| [T] (
|
|
1797
|
+
def fetch: (int index) -> E
|
|
1798
|
+
| [T] (int index, T default) -> (E | T)
|
|
1799
|
+
| [I < _ToInt, T] (I index) { (I index) -> T } -> (E | T)
|
|
1767
1800
|
|
|
1768
1801
|
# <!--
|
|
1769
1802
|
# rdoc-file=array.rb
|
|
@@ -1800,14 +1833,15 @@ class Array[unchecked out Elem] < Object
|
|
|
1800
1833
|
#
|
|
1801
1834
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1802
1835
|
#
|
|
1803
|
-
def fetch_values: (*int indexes) ->
|
|
1836
|
+
def fetch_values: (*int indexes) -> Array[E]
|
|
1837
|
+
| [I < _ToInt, T] (*I indexes) { (I index) -> T } -> Array[E | T]
|
|
1804
1838
|
|
|
1805
1839
|
# <!--
|
|
1806
1840
|
# rdoc-file=array.c
|
|
1807
|
-
# - fill(object, start = nil, count = nil) ->
|
|
1808
|
-
# - fill(object, range) ->
|
|
1809
|
-
# - fill(start = nil, count = nil) {|element| ... } ->
|
|
1810
|
-
# - fill(range) {|element| ... } ->
|
|
1841
|
+
# - fill(object, start = nil, count = nil) -> self
|
|
1842
|
+
# - fill(object, range) -> self
|
|
1843
|
+
# - fill(start = nil, count = nil) {|element| ... } -> self
|
|
1844
|
+
# - fill(range) {|element| ... } -> self
|
|
1811
1845
|
# -->
|
|
1812
1846
|
# Replaces selected elements in `self`; may add elements to `self`; always
|
|
1813
1847
|
# returns `self` (never a new array).
|
|
@@ -1980,11 +2014,10 @@ class Array[unchecked out Elem] < Object
|
|
|
1980
2014
|
#
|
|
1981
2015
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
1982
2016
|
#
|
|
1983
|
-
def fill: (
|
|
1984
|
-
| (
|
|
1985
|
-
| (
|
|
1986
|
-
| (
|
|
1987
|
-
| (::Range[::Integer] range) { (::Integer index) -> Elem } -> self
|
|
2017
|
+
def fill: (E object, ?int? start, ?int? length) -> self
|
|
2018
|
+
| (E object, range[int?] range) -> self
|
|
2019
|
+
| (?int? start, ?int? length) { (Integer index) -> E } -> self
|
|
2020
|
+
| (range[int?] range) { (Integer index) -> E } -> self
|
|
1988
2021
|
|
|
1989
2022
|
# <!-- rdoc-file=array.c -->
|
|
1990
2023
|
# With a block given, calls the block with each element of `self`; returns a new
|
|
@@ -1999,8 +2032,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1999
2032
|
#
|
|
2000
2033
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
2001
2034
|
#
|
|
2002
|
-
|
|
2003
|
-
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
|
2035
|
+
alias filter select
|
|
2004
2036
|
|
|
2005
2037
|
# <!-- rdoc-file=array.c -->
|
|
2006
2038
|
# With a block given, calls the block with each element of `self`; removes from
|
|
@@ -2017,8 +2049,31 @@ class Array[unchecked out Elem] < Object
|
|
|
2017
2049
|
#
|
|
2018
2050
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
2019
2051
|
#
|
|
2020
|
-
|
|
2021
|
-
|
|
2052
|
+
alias filter! select!
|
|
2053
|
+
|
|
2054
|
+
# <!--
|
|
2055
|
+
# rdoc-file=array.c
|
|
2056
|
+
# - find(if_none_proc = nil) {|element| ... } -> object or nil
|
|
2057
|
+
# - find(if_none_proc = nil) -> enumerator
|
|
2058
|
+
# -->
|
|
2059
|
+
# Returns the first element for which the block returns a truthy value.
|
|
2060
|
+
#
|
|
2061
|
+
# With a block given, calls the block with successive elements of the array;
|
|
2062
|
+
# returns the first element for which the block returns a truthy value:
|
|
2063
|
+
#
|
|
2064
|
+
# [1, 3, 5].find {|element| element > 2} # => 3
|
|
2065
|
+
#
|
|
2066
|
+
# If no such element is found, calls `if_none_proc` and returns its return
|
|
2067
|
+
# value.
|
|
2068
|
+
#
|
|
2069
|
+
# [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1
|
|
2070
|
+
#
|
|
2071
|
+
# With no block given, returns an Enumerator.
|
|
2072
|
+
#
|
|
2073
|
+
def find: () { (E) -> boolish } -> E?
|
|
2074
|
+
| () -> Enumerator[E, E?]
|
|
2075
|
+
| [T] (Enumerable::_NotFound[T]? ifnone) { (E) -> boolish } -> (E | T)
|
|
2076
|
+
| [T] (Enumerable::_NotFound[T]? ifnone) -> Enumerator[E, E | T]
|
|
2022
2077
|
|
|
2023
2078
|
# <!--
|
|
2024
2079
|
# rdoc-file=array.c
|
|
@@ -2032,7 +2087,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2032
2087
|
# Returns the zero-based integer index of a specified element, or `nil`.
|
|
2033
2088
|
#
|
|
2034
2089
|
# With only argument `object` given, returns the index of the first element
|
|
2035
|
-
# `element` for which
|
|
2090
|
+
# `element` for which <code>object == element</code>:
|
|
2036
2091
|
#
|
|
2037
2092
|
# a = [:foo, 'bar', 2, 'bar']
|
|
2038
2093
|
# a.index('bar') # => 1
|
|
@@ -2051,9 +2106,9 @@ class Array[unchecked out Elem] < Object
|
|
|
2051
2106
|
#
|
|
2052
2107
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2053
2108
|
#
|
|
2054
|
-
def find_index: (untyped
|
|
2055
|
-
| () { (
|
|
2056
|
-
| () ->
|
|
2109
|
+
def find_index: (untyped object) -> Integer? # where E: RBS::Ops::_Equal
|
|
2110
|
+
| () { (E element) -> boolish } -> Integer?
|
|
2111
|
+
| () -> Enumerator[E, Integer?]
|
|
2057
2112
|
|
|
2058
2113
|
# <!--
|
|
2059
2114
|
# rdoc-file=array.rb
|
|
@@ -2081,8 +2136,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2081
2136
|
#
|
|
2082
2137
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2083
2138
|
#
|
|
2084
|
-
def first: %a{implicitly-returns-nil} () ->
|
|
2085
|
-
| (int
|
|
2139
|
+
def first: %a{implicitly-returns-nil} () -> E
|
|
2140
|
+
| (int count) -> Array[E]
|
|
2086
2141
|
|
|
2087
2142
|
# <!--
|
|
2088
2143
|
# rdoc-file=array.c
|
|
@@ -2117,7 +2172,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2117
2172
|
# Related: Array#flatten!; see also [Methods for
|
|
2118
2173
|
# Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
2119
2174
|
#
|
|
2120
|
-
def flatten: (?int level) ->
|
|
2175
|
+
def flatten: (?int? level) -> Array[untyped]
|
|
2121
2176
|
|
|
2122
2177
|
# <!--
|
|
2123
2178
|
# rdoc-file=array.c
|
|
@@ -2153,7 +2208,25 @@ class Array[unchecked out Elem] < Object
|
|
|
2153
2208
|
# Related: Array#flatten; see also [Methods for
|
|
2154
2209
|
# Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
2155
2210
|
#
|
|
2156
|
-
def flatten!: (?int level) -> self?
|
|
2211
|
+
def flatten!: (?int? level) -> self?
|
|
2212
|
+
|
|
2213
|
+
# <!--
|
|
2214
|
+
# rdoc-file=array.c
|
|
2215
|
+
# - freeze -> self
|
|
2216
|
+
# -->
|
|
2217
|
+
# Freezes `self` (if not already frozen); returns `self`:
|
|
2218
|
+
#
|
|
2219
|
+
# a = []
|
|
2220
|
+
# a.frozen? # => false
|
|
2221
|
+
# a.freeze
|
|
2222
|
+
# a.frozen? # => true
|
|
2223
|
+
#
|
|
2224
|
+
# No further changes may be made to `self`; raises FrozenError if a change is
|
|
2225
|
+
# attempted.
|
|
2226
|
+
#
|
|
2227
|
+
# Related: Kernel#frozen?.
|
|
2228
|
+
#
|
|
2229
|
+
def freeze: () -> self
|
|
2157
2230
|
|
|
2158
2231
|
# <!--
|
|
2159
2232
|
# rdoc-file=array.c
|
|
@@ -2168,13 +2241,14 @@ class Array[unchecked out Elem] < Object
|
|
|
2168
2241
|
# ['a', 'b'].hash == ['a', 'c'].hash # => false
|
|
2169
2242
|
# ['a', 'b'].hash == ['a'].hash # => false
|
|
2170
2243
|
#
|
|
2171
|
-
def hash: () ->
|
|
2244
|
+
def hash: () -> Integer # where E: _Hash
|
|
2172
2245
|
|
|
2173
2246
|
# <!--
|
|
2174
2247
|
# rdoc-file=array.c
|
|
2175
2248
|
# - include?(object) -> true or false
|
|
2176
2249
|
# -->
|
|
2177
|
-
# Returns whether for some element `element` in `self`,
|
|
2250
|
+
# Returns whether for some element `element` in `self`, <code>object ==
|
|
2251
|
+
# element</code>:
|
|
2178
2252
|
#
|
|
2179
2253
|
# [0, 1, 2].include?(2) # => true
|
|
2180
2254
|
# [0, 1, 2].include?(2.0) # => true
|
|
@@ -2182,13 +2256,13 @@ class Array[unchecked out Elem] < Object
|
|
|
2182
2256
|
#
|
|
2183
2257
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2184
2258
|
#
|
|
2185
|
-
def include?: (
|
|
2259
|
+
def include?: (untyped object) -> bool # where E: RBS::Ops::_Equals
|
|
2186
2260
|
|
|
2187
2261
|
# <!-- rdoc-file=array.c -->
|
|
2188
2262
|
# Returns the zero-based integer index of a specified element, or `nil`.
|
|
2189
2263
|
#
|
|
2190
2264
|
# With only argument `object` given, returns the index of the first element
|
|
2191
|
-
# `element` for which
|
|
2265
|
+
# `element` for which <code>object == element</code>:
|
|
2192
2266
|
#
|
|
2193
2267
|
# a = [:foo, 'bar', 2, 'bar']
|
|
2194
2268
|
# a.index('bar') # => 1
|
|
@@ -2221,13 +2295,14 @@ class Array[unchecked out Elem] < Object
|
|
|
2221
2295
|
# a = ['a', 'b', 'c'] # => ["a", "b", "c"]
|
|
2222
2296
|
# a.insert(1, :x, :y, :z) # => ["a", :x, :y, :z, "b", "c"]
|
|
2223
2297
|
#
|
|
2224
|
-
# Extends the array if `index` is beyond the array (
|
|
2298
|
+
# Extends the array if `index` is beyond the array (<code>index >=
|
|
2299
|
+
# self.size</code>):
|
|
2225
2300
|
#
|
|
2226
2301
|
# a = ['a', 'b', 'c'] # => ["a", "b", "c"]
|
|
2227
2302
|
# a.insert(5, :x, :y, :z) # => ["a", "b", "c", nil, nil, :x, :y, :z]
|
|
2228
2303
|
#
|
|
2229
2304
|
# When `index` is negative, inserts `objects` *after* the element at offset
|
|
2230
|
-
#
|
|
2305
|
+
# <code>index + self.size</code>:
|
|
2231
2306
|
#
|
|
2232
2307
|
# a = ['a', 'b', 'c'] # => ["a", "b", "c"]
|
|
2233
2308
|
# a.insert(-2, :x, :y, :z) # => ["a", "b", :x, :y, :z, "c"]
|
|
@@ -2244,49 +2319,50 @@ class Array[unchecked out Elem] < Object
|
|
|
2244
2319
|
#
|
|
2245
2320
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
2246
2321
|
#
|
|
2247
|
-
def insert: (int index, *
|
|
2322
|
+
def insert: (int index, *E objects) -> self
|
|
2248
2323
|
|
|
2249
2324
|
# <!--
|
|
2250
2325
|
# rdoc-file=array.c
|
|
2251
2326
|
# - inspect -> new_string
|
|
2252
2327
|
# - to_s -> new_string
|
|
2253
2328
|
# -->
|
|
2254
|
-
# Returns the new string formed by calling method
|
|
2255
|
-
# element:
|
|
2329
|
+
# Returns the new string formed by calling method <code>#inspect</code> on each
|
|
2330
|
+
# array element:
|
|
2256
2331
|
#
|
|
2257
2332
|
# a = [:foo, 'bar', 2]
|
|
2258
2333
|
# a.inspect # => "[:foo, \"bar\", 2]"
|
|
2259
2334
|
#
|
|
2260
2335
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
2261
2336
|
#
|
|
2262
|
-
def inspect: () -> String
|
|
2337
|
+
def inspect: () -> String # where E: _Inspect
|
|
2263
2338
|
|
|
2264
2339
|
# <!--
|
|
2265
2340
|
# rdoc-file=array.c
|
|
2266
2341
|
# - intersect?(other_array) -> true or false
|
|
2267
2342
|
# -->
|
|
2268
|
-
# Returns whether `other_array` has at least one element that is
|
|
2269
|
-
# element of `self`:
|
|
2343
|
+
# Returns whether `other_array` has at least one element that is
|
|
2344
|
+
# <code>#eql?</code> to some element of `self`:
|
|
2270
2345
|
#
|
|
2271
2346
|
# [1, 2, 3].intersect?([3, 4, 5]) # => true
|
|
2272
2347
|
# [1, 2, 3].intersect?([4, 5, 6]) # => false
|
|
2273
2348
|
#
|
|
2274
|
-
# Each element must correctly implement method
|
|
2349
|
+
# Each element must correctly implement method <code>#hash</code>.
|
|
2275
2350
|
#
|
|
2276
2351
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2277
2352
|
#
|
|
2278
|
-
def intersect?: (
|
|
2353
|
+
def intersect?: (array[untyped] other_array) -> bool # where E: _Eql?
|
|
2279
2354
|
|
|
2280
2355
|
# <!--
|
|
2281
2356
|
# rdoc-file=array.c
|
|
2282
2357
|
# - intersection(*other_arrays) -> new_array
|
|
2283
2358
|
# -->
|
|
2284
|
-
# Returns a new array containing each element in `self` that is
|
|
2285
|
-
# least one element in each of the given
|
|
2359
|
+
# Returns a new array containing each element in `self` that is
|
|
2360
|
+
# <code>#eql?</code> to at least one element in each of the given
|
|
2361
|
+
# `other_arrays`; duplicates are omitted:
|
|
2286
2362
|
#
|
|
2287
2363
|
# [0, 0, 1, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
|
|
2288
2364
|
#
|
|
2289
|
-
# Each element must correctly implement method
|
|
2365
|
+
# Each element must correctly implement method <code>#hash</code>.
|
|
2290
2366
|
#
|
|
2291
2367
|
# Order from `self` is preserved:
|
|
2292
2368
|
#
|
|
@@ -2296,20 +2372,21 @@ class Array[unchecked out Elem] < Object
|
|
|
2296
2372
|
#
|
|
2297
2373
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
2298
2374
|
#
|
|
2299
|
-
def intersection: (
|
|
2375
|
+
def intersection: (*array[untyped] other_arrays) -> Array[E] # where E: _Eql?
|
|
2300
2376
|
|
|
2301
2377
|
# <!--
|
|
2302
2378
|
# rdoc-file=array.c
|
|
2303
|
-
# -
|
|
2379
|
+
# - join(separator = $,) -> new_string
|
|
2304
2380
|
# -->
|
|
2305
2381
|
# Returns the new string formed by joining the converted elements of `self`; for
|
|
2306
2382
|
# each element `element`:
|
|
2307
2383
|
#
|
|
2308
|
-
# * Converts recursively using
|
|
2309
|
-
# `kind_of?(Array)
|
|
2310
|
-
# * Otherwise, converts using
|
|
2384
|
+
# * Converts recursively using <code>element.join(separator)</code> if
|
|
2385
|
+
# `element` is a <code>kind_of?(Array)</code>.
|
|
2386
|
+
# * Otherwise, converts using <code>element.to_s</code>.
|
|
2311
2387
|
#
|
|
2312
|
-
# With no argument given, joins using the output field separator,
|
|
2388
|
+
# With no argument given, joins using the output field separator,
|
|
2389
|
+
# <code>$,</code>:
|
|
2313
2390
|
#
|
|
2314
2391
|
# a = [:foo, 'bar', 2]
|
|
2315
2392
|
# $, # => nil
|
|
@@ -2327,7 +2404,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2327
2404
|
#
|
|
2328
2405
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
2329
2406
|
#
|
|
2330
|
-
def join: (?string separator) -> String
|
|
2407
|
+
def join: (?string? separator) -> String # where E: _ToS
|
|
2331
2408
|
|
|
2332
2409
|
# <!--
|
|
2333
2410
|
# rdoc-file=array.c
|
|
@@ -2344,8 +2421,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2344
2421
|
#
|
|
2345
2422
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
2346
2423
|
#
|
|
2347
|
-
def keep_if: () { (
|
|
2348
|
-
| () ->
|
|
2424
|
+
def keep_if: () { (E element) -> boolish } -> self
|
|
2425
|
+
| () -> Enumerator[E, self]
|
|
2349
2426
|
|
|
2350
2427
|
# <!--
|
|
2351
2428
|
# rdoc-file=array.rb
|
|
@@ -2372,8 +2449,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2372
2449
|
#
|
|
2373
2450
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
2374
2451
|
#
|
|
2375
|
-
def last: %a{implicitly-returns-nil} () ->
|
|
2376
|
-
| (int
|
|
2452
|
+
def last: %a{implicitly-returns-nil} () -> E
|
|
2453
|
+
| (int count) -> Array[E]
|
|
2377
2454
|
|
|
2378
2455
|
# <!--
|
|
2379
2456
|
# rdoc-file=array.c
|
|
@@ -2387,7 +2464,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2387
2464
|
#
|
|
2388
2465
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2389
2466
|
#
|
|
2390
|
-
def length: () ->
|
|
2467
|
+
def length: () -> Integer
|
|
2391
2468
|
|
|
2392
2469
|
# <!-- rdoc-file=array.c -->
|
|
2393
2470
|
# With a block given, calls the block with each element of `self`; returns a new
|
|
@@ -2432,16 +2509,17 @@ class Array[unchecked out Elem] < Object
|
|
|
2432
2509
|
#
|
|
2433
2510
|
# Does not modify `self`.
|
|
2434
2511
|
#
|
|
2435
|
-
# With no block given, each element in `self` must respond to method
|
|
2436
|
-
# a numeric.
|
|
2512
|
+
# With no block given, each element in `self` must respond to method
|
|
2513
|
+
# <code>#<=></code> with a numeric.
|
|
2437
2514
|
#
|
|
2438
2515
|
# With no argument and no block, returns the element in `self` having the
|
|
2439
|
-
# maximum value per method
|
|
2516
|
+
# maximum value per method <code>#<=></code>:
|
|
2440
2517
|
#
|
|
2441
2518
|
# [1, 0, 3, 2].max # => 3
|
|
2442
2519
|
#
|
|
2443
2520
|
# With non-negative numeric argument `count` and no block, returns a new array
|
|
2444
|
-
# with at most `count` elements, in descending order, per method
|
|
2521
|
+
# with at most `count` elements, in descending order, per method
|
|
2522
|
+
# <code>#<=></code>:
|
|
2445
2523
|
#
|
|
2446
2524
|
# [1, 0, 3, 2].max(3) # => [3, 2, 1]
|
|
2447
2525
|
# [1, 0, 3, 2].max(3.0) # => [3, 2, 1]
|
|
@@ -2450,8 +2528,9 @@ class Array[unchecked out Elem] < Object
|
|
|
2450
2528
|
#
|
|
2451
2529
|
# With a block given, the block must return a numeric.
|
|
2452
2530
|
#
|
|
2453
|
-
# With a block and no argument, calls the block
|
|
2454
|
-
# elements; returns the element having the maximum value per the
|
|
2531
|
+
# With a block and no argument, calls the block <code>self.size - 1</code> times
|
|
2532
|
+
# to compare elements; returns the element having the maximum value per the
|
|
2533
|
+
# block:
|
|
2455
2534
|
#
|
|
2456
2535
|
# ['0', '', '000', '00'].max {|a, b| a.size <=> b.size }
|
|
2457
2536
|
# # => "000"
|
|
@@ -2464,10 +2543,12 @@ class Array[unchecked out Elem] < Object
|
|
|
2464
2543
|
#
|
|
2465
2544
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
2466
2545
|
#
|
|
2467
|
-
def max: %a{implicitly-returns-nil} () ->
|
|
2468
|
-
| %a{implicitly-returns-nil} () { (
|
|
2469
|
-
| (
|
|
2470
|
-
| (int
|
|
2546
|
+
def max: %a{implicitly-returns-nil} () -> E # where E: Comparable::_WithSpaceshipOperator
|
|
2547
|
+
| %a{implicitly-returns-nil} () { (E a, E b) -> Comparable::_CompareToZero } -> E
|
|
2548
|
+
| %a{implicitly-returns-nil} %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> E
|
|
2549
|
+
| (int count) -> Array[E] # where E: Comparable::_WithSpaceshipOperator
|
|
2550
|
+
| (int count) { (E a, E b) -> Comparable::_CompareToZero } -> Array[E]
|
|
2551
|
+
| %a{warning: returning `nil` will always raise at runtime} (int count) { (E a, E b) -> Comparable::_CompareToZero? } -> Array[E]
|
|
2471
2552
|
|
|
2472
2553
|
# <!--
|
|
2473
2554
|
# rdoc-file=array.c
|
|
@@ -2483,16 +2564,17 @@ class Array[unchecked out Elem] < Object
|
|
|
2483
2564
|
#
|
|
2484
2565
|
# Does not modify `self`.
|
|
2485
2566
|
#
|
|
2486
|
-
# With no block given, each element in `self` must respond to method
|
|
2487
|
-
# a numeric.
|
|
2567
|
+
# With no block given, each element in `self` must respond to method
|
|
2568
|
+
# <code>#<=></code> with a numeric.
|
|
2488
2569
|
#
|
|
2489
2570
|
# With no argument and no block, returns the element in `self` having the
|
|
2490
|
-
# minimum value per method
|
|
2571
|
+
# minimum value per method <code>#<=></code>:
|
|
2491
2572
|
#
|
|
2492
2573
|
# [1, 0, 3, 2].min # => 0
|
|
2493
2574
|
#
|
|
2494
2575
|
# With non-negative numeric argument `count` and no block, returns a new array
|
|
2495
|
-
# with at most `count` elements, in ascending order, per method
|
|
2576
|
+
# with at most `count` elements, in ascending order, per method
|
|
2577
|
+
# <code>#<=></code>:
|
|
2496
2578
|
#
|
|
2497
2579
|
# [1, 0, 3, 2].min(3) # => [0, 1, 2]
|
|
2498
2580
|
# [1, 0, 3, 2].min(3.0) # => [0, 1, 2]
|
|
@@ -2501,8 +2583,9 @@ class Array[unchecked out Elem] < Object
|
|
|
2501
2583
|
#
|
|
2502
2584
|
# With a block given, the block must return a numeric.
|
|
2503
2585
|
#
|
|
2504
|
-
# With a block and no argument, calls the block
|
|
2505
|
-
# elements; returns the element having the minimum value per the
|
|
2586
|
+
# With a block and no argument, calls the block <code>self.size - 1</code> times
|
|
2587
|
+
# to compare elements; returns the element having the minimum value per the
|
|
2588
|
+
# block:
|
|
2506
2589
|
#
|
|
2507
2590
|
# ['0', '', '000', '00'].min {|a, b| a.size <=> b.size }
|
|
2508
2591
|
# # => ""
|
|
@@ -2515,7 +2598,12 @@ class Array[unchecked out Elem] < Object
|
|
|
2515
2598
|
#
|
|
2516
2599
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
2517
2600
|
#
|
|
2518
|
-
|
|
2601
|
+
def min: %a{implicitly-returns-nil} () -> E # where E: Comparable::_WithSpaceshipOperator
|
|
2602
|
+
| %a{implicitly-returns-nil} () { (E a, E b) -> Comparable::_CompareToZero } -> E
|
|
2603
|
+
| %a{implicitly-returns-nil} %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> E
|
|
2604
|
+
| (int count) -> Array[E] # where E: Comparable::_WithSpaceshipOperator
|
|
2605
|
+
| (int count) { (E a, E b) -> Comparable::_CompareToZero } -> Array[E]
|
|
2606
|
+
| %a{warning: returning `nil` will always raise at runtime} (int count) { (E a, E b) -> Comparable::_CompareToZero? } -> Array[E]
|
|
2519
2607
|
|
|
2520
2608
|
# <!--
|
|
2521
2609
|
# rdoc-file=array.c
|
|
@@ -2526,21 +2614,22 @@ class Array[unchecked out Elem] < Object
|
|
|
2526
2614
|
# elements from `self`; does not modify `self`.
|
|
2527
2615
|
#
|
|
2528
2616
|
# With no block given, the minimum and maximum values are determined using
|
|
2529
|
-
# method
|
|
2617
|
+
# method <code>#<=></code>:
|
|
2530
2618
|
#
|
|
2531
2619
|
# [1, 0, 3, 2].minmax # => [0, 3]
|
|
2532
2620
|
#
|
|
2533
2621
|
# With a block given, the block must return a numeric; the block is called
|
|
2534
|
-
#
|
|
2535
|
-
# minimum and maximum values per the block:
|
|
2622
|
+
# <code>self.size - 1</code> times to compare elements; returns the elements
|
|
2623
|
+
# having the minimum and maximum values per the block:
|
|
2536
2624
|
#
|
|
2537
2625
|
# ['0', '', '000', '00'].minmax {|a, b| a.size <=> b.size }
|
|
2538
2626
|
# # => ["", "000"]
|
|
2539
2627
|
#
|
|
2540
2628
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
2541
2629
|
#
|
|
2542
|
-
def minmax: () -> [
|
|
2543
|
-
| () { (
|
|
2630
|
+
def minmax: () -> [ E?, E? ] # where E: Comparable::_WithSpaceshipOperator
|
|
2631
|
+
| () { (E a, E b) -> Comparable::_CompareToZero } -> [ E?, E? ]
|
|
2632
|
+
| %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> [ E?, E? ]
|
|
2544
2633
|
|
|
2545
2634
|
# <!--
|
|
2546
2635
|
# rdoc-file=array.c
|
|
@@ -2559,7 +2648,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2559
2648
|
# [].none? # => true
|
|
2560
2649
|
#
|
|
2561
2650
|
# With argument `object` given, returns `false` if for any element `element`,
|
|
2562
|
-
#
|
|
2651
|
+
# <code>object === element</code>; `true` otherwise:
|
|
2563
2652
|
#
|
|
2564
2653
|
# ['food', 'drink'].none?(/bar/) # => true
|
|
2565
2654
|
# ['food', 'drink'].none?(/foo/) # => false
|
|
@@ -2575,7 +2664,9 @@ class Array[unchecked out Elem] < Object
|
|
|
2575
2664
|
#
|
|
2576
2665
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2577
2666
|
#
|
|
2578
|
-
|
|
2667
|
+
def none?: () -> bool
|
|
2668
|
+
| (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
|
|
2669
|
+
| () { (E element) -> boolish } -> bool
|
|
2579
2670
|
|
|
2580
2671
|
# <!--
|
|
2581
2672
|
# rdoc-file=array.c
|
|
@@ -2601,7 +2692,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2601
2692
|
# [0, 1, 2].one? {|element| element > 2 } # => false
|
|
2602
2693
|
#
|
|
2603
2694
|
# With argument `object` given, returns `true` if for exactly one element
|
|
2604
|
-
# `element`,
|
|
2695
|
+
# `element`, <code>object === element</code>; `false` otherwise:
|
|
2605
2696
|
#
|
|
2606
2697
|
# [0, 1, 2].one?(0) # => true
|
|
2607
2698
|
# [0, 0, 1].one?(0) # => false
|
|
@@ -2612,14 +2703,16 @@ class Array[unchecked out Elem] < Object
|
|
|
2612
2703
|
#
|
|
2613
2704
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
2614
2705
|
#
|
|
2615
|
-
|
|
2706
|
+
def one?: () -> bool
|
|
2707
|
+
| (RBS::Ops::_CaseEqual[E, boolish] pattern) -> bool
|
|
2708
|
+
| () { (E element) -> boolish } -> bool
|
|
2616
2709
|
|
|
2617
2710
|
# <!--
|
|
2618
2711
|
# rdoc-file=pack.rb
|
|
2619
2712
|
# - pack(template, buffer: nil) -> string
|
|
2620
2713
|
# -->
|
|
2621
2714
|
# Formats each element in `self` into a binary string; returns that string. See
|
|
2622
|
-
# [Packed Data](rdoc-ref:packed_data.rdoc).
|
|
2715
|
+
# [Packed Data](rdoc-ref:language/packed_data.rdoc).
|
|
2623
2716
|
#
|
|
2624
2717
|
def pack: (string fmt, ?buffer: String?) -> String
|
|
2625
2718
|
|
|
@@ -2631,9 +2724,9 @@ class Array[unchecked out Elem] < Object
|
|
|
2631
2724
|
# Iterates over permutations of the elements of `self`; the order of
|
|
2632
2725
|
# permutations is indeterminate.
|
|
2633
2726
|
#
|
|
2634
|
-
# With a block and an in-range positive integer argument `count` (
|
|
2635
|
-
# self.size
|
|
2636
|
-
# `count`; returns `self`:
|
|
2727
|
+
# With a block and an in-range positive integer argument `count` (<code>0 <
|
|
2728
|
+
# count <= self.size</code>) given, calls the block with each permutation of
|
|
2729
|
+
# `self` of size `count`; returns `self`:
|
|
2637
2730
|
#
|
|
2638
2731
|
# a = [0, 1, 2]
|
|
2639
2732
|
# perms = []
|
|
@@ -2654,8 +2747,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2654
2747
|
# a.permutation(0) {|perm| perms.push(perm) }
|
|
2655
2748
|
# perms # => [[]]
|
|
2656
2749
|
#
|
|
2657
|
-
# When `count` is out of range (negative or larger than
|
|
2658
|
-
# call the block:
|
|
2750
|
+
# When `count` is out of range (negative or larger than <code>self.size</code>),
|
|
2751
|
+
# does not call the block:
|
|
2659
2752
|
#
|
|
2660
2753
|
# a.permutation(-1) {|permutation| fail 'Cannot happen' }
|
|
2661
2754
|
# a.permutation(4) {|permutation| fail 'Cannot happen' }
|
|
@@ -2664,8 +2757,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2664
2757
|
#
|
|
2665
2758
|
# Related: [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
|
|
2666
2759
|
#
|
|
2667
|
-
def permutation: (?int
|
|
2668
|
-
| (?int
|
|
2760
|
+
def permutation: (?int? count) { (Array[E] permutation) -> void } -> self
|
|
2761
|
+
| (?int? count) -> Enumerator[Array[E], self]
|
|
2669
2762
|
|
|
2670
2763
|
# <!--
|
|
2671
2764
|
# rdoc-file=array.c
|
|
@@ -2696,8 +2789,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2696
2789
|
# Related: Array#push; see also [Methods for
|
|
2697
2790
|
# Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
2698
2791
|
#
|
|
2699
|
-
def pop: () ->
|
|
2700
|
-
| (int
|
|
2792
|
+
def pop: () -> E?
|
|
2793
|
+
| (int count) -> Array[E]
|
|
2701
2794
|
|
|
2702
2795
|
# <!-- rdoc-file=array.c -->
|
|
2703
2796
|
# Prepends the given `objects` to `self`:
|
|
@@ -2763,10 +2856,14 @@ class Array[unchecked out Elem] < Object
|
|
|
2763
2856
|
#
|
|
2764
2857
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
2765
2858
|
#
|
|
2766
|
-
def product: () ->
|
|
2767
|
-
|
|
|
2768
|
-
| [X
|
|
2769
|
-
| [
|
|
2859
|
+
def product: () -> Array[[ E ]]
|
|
2860
|
+
| () { ([E] combination) -> void } -> self
|
|
2861
|
+
| [X] (array[X] other_ary) -> Array[[ E, X ]]
|
|
2862
|
+
| [X] (array[X] other_ary) { ([E, X] combination) -> void } -> self
|
|
2863
|
+
| [X, Y] (array[X] other_ary1, array[Y] other_ary2) -> Array[[ E, X, Y ]]
|
|
2864
|
+
| [X, Y] (array[X] other_ary1, array[Y] other_ary2) { ([E, X, Y] combination) -> void } -> self
|
|
2865
|
+
| [U] (*array[U] other_arys) -> Array[Array[E | U]]
|
|
2866
|
+
| [U] (*array[U] other_arys) { (Array[E | U] combination) -> void } -> self
|
|
2770
2867
|
|
|
2771
2868
|
# <!--
|
|
2772
2869
|
# rdoc-file=array.c
|
|
@@ -2785,14 +2882,14 @@ class Array[unchecked out Elem] < Object
|
|
|
2785
2882
|
#
|
|
2786
2883
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
2787
2884
|
#
|
|
2788
|
-
def push: (*
|
|
2885
|
+
def push: (*E objects) -> self
|
|
2789
2886
|
|
|
2790
2887
|
# <!--
|
|
2791
2888
|
# rdoc-file=array.c
|
|
2792
2889
|
# - rassoc(object) -> found_array or nil
|
|
2793
2890
|
# -->
|
|
2794
2891
|
# Returns the first element `ele` in `self` such that `ele` is an array and
|
|
2795
|
-
#
|
|
2892
|
+
# <code>ele[1] == object</code>:
|
|
2796
2893
|
#
|
|
2797
2894
|
# a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
|
|
2798
2895
|
# a.rassoc(4) # => [2, 4]
|
|
@@ -2803,7 +2900,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2803
2900
|
# Related: Array#assoc; see also [Methods for
|
|
2804
2901
|
# Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
2805
2902
|
#
|
|
2806
|
-
|
|
2903
|
+
def rassoc: (untyped object) -> Array[untyped]? # where E: _ToAry, object: _Equal
|
|
2807
2904
|
|
|
2808
2905
|
# <!--
|
|
2809
2906
|
# rdoc-file=array.c
|
|
@@ -2842,8 +2939,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2842
2939
|
#
|
|
2843
2940
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
2844
2941
|
#
|
|
2845
|
-
def reject!: () { (
|
|
2846
|
-
| () ->
|
|
2942
|
+
def reject!: () { (E item) -> boolish } -> self?
|
|
2943
|
+
| () -> Enumerator[E, self?]
|
|
2847
2944
|
|
|
2848
2945
|
# <!--
|
|
2849
2946
|
# rdoc-file=array.c
|
|
@@ -2856,7 +2953,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2856
2953
|
#
|
|
2857
2954
|
# If a positive integer argument `size` is given, calls the block with each
|
|
2858
2955
|
# `size`-tuple repeated combination of the elements of `self`. The number of
|
|
2859
|
-
# combinations is
|
|
2956
|
+
# combinations is <code>(size+1)(size+2)/2</code>.
|
|
2860
2957
|
#
|
|
2861
2958
|
# Examples:
|
|
2862
2959
|
#
|
|
@@ -2882,8 +2979,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2882
2979
|
#
|
|
2883
2980
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
2884
2981
|
#
|
|
2885
|
-
def repeated_combination: (int
|
|
2886
|
-
| (int
|
|
2982
|
+
def repeated_combination: (int size) { (Array[E] combination) -> void } -> self
|
|
2983
|
+
| (int size) -> Enumerator[Array[E], self]
|
|
2887
2984
|
|
|
2888
2985
|
# <!--
|
|
2889
2986
|
# rdoc-file=array.c
|
|
@@ -2896,7 +2993,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2896
2993
|
#
|
|
2897
2994
|
# If a positive integer argument `size` is given, calls the block with each
|
|
2898
2995
|
# `size`-tuple repeated permutation of the elements of `self`. The number of
|
|
2899
|
-
# permutations is
|
|
2996
|
+
# permutations is <code>self.size**size</code>.
|
|
2900
2997
|
#
|
|
2901
2998
|
# Examples:
|
|
2902
2999
|
#
|
|
@@ -2922,8 +3019,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2922
3019
|
#
|
|
2923
3020
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
2924
3021
|
#
|
|
2925
|
-
def repeated_permutation: (int
|
|
2926
|
-
| (int
|
|
3022
|
+
def repeated_permutation: (int size) { (Array[E] permutation) -> void } -> self
|
|
3023
|
+
| (int size) -> Enumerator[Array[E], self]
|
|
2927
3024
|
|
|
2928
3025
|
# <!-- rdoc-file=array.c -->
|
|
2929
3026
|
# Replaces the elements of `self` with the elements of `other_array`, which must
|
|
@@ -2936,7 +3033,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2936
3033
|
#
|
|
2937
3034
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
2938
3035
|
#
|
|
2939
|
-
def replace: (
|
|
3036
|
+
def replace: (array[E] other_array) -> self
|
|
2940
3037
|
|
|
2941
3038
|
# <!--
|
|
2942
3039
|
# rdoc-file=array.c
|
|
@@ -2948,7 +3045,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2948
3045
|
#
|
|
2949
3046
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
2950
3047
|
#
|
|
2951
|
-
def reverse: () ->
|
|
3048
|
+
def reverse: () -> Array[E]
|
|
2952
3049
|
|
|
2953
3050
|
# <!--
|
|
2954
3051
|
# rdoc-file=array.c
|
|
@@ -2962,7 +3059,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2962
3059
|
#
|
|
2963
3060
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
2964
3061
|
#
|
|
2965
|
-
def reverse!: () ->
|
|
3062
|
+
def reverse!: () -> self
|
|
2966
3063
|
|
|
2967
3064
|
# <!--
|
|
2968
3065
|
# rdoc-file=array.c
|
|
@@ -2986,8 +3083,33 @@ class Array[unchecked out Elem] < Object
|
|
|
2986
3083
|
#
|
|
2987
3084
|
# Related: see [Methods for Iterating](rdoc-ref:Array@Methods+for+Iterating).
|
|
2988
3085
|
#
|
|
2989
|
-
def reverse_each: () { (
|
|
2990
|
-
| () ->
|
|
3086
|
+
def reverse_each: () { (E element) -> void } -> self
|
|
3087
|
+
| () -> Enumerator[E, self]
|
|
3088
|
+
|
|
3089
|
+
# <!--
|
|
3090
|
+
# rdoc-file=array.c
|
|
3091
|
+
# - rfind(if_none_proc = nil) {|element| ... } -> object or nil
|
|
3092
|
+
# - rfind(if_none_proc = nil) -> enumerator
|
|
3093
|
+
# -->
|
|
3094
|
+
# Returns the last element for which the block returns a truthy value.
|
|
3095
|
+
#
|
|
3096
|
+
# With a block given, calls the block with successive elements of the array in
|
|
3097
|
+
# reverse order; returns the first element for which the block returns a truthy
|
|
3098
|
+
# value:
|
|
3099
|
+
#
|
|
3100
|
+
# [1, 2, 3, 4, 5, 6].rfind {|element| element < 5} # => 4
|
|
3101
|
+
#
|
|
3102
|
+
# If no such element is found, calls `if_none_proc` and returns its return
|
|
3103
|
+
# value.
|
|
3104
|
+
#
|
|
3105
|
+
# [1, 2, 3, 4].rfind(proc {0}) {|element| element < -2} # => 0
|
|
3106
|
+
#
|
|
3107
|
+
# With no block given, returns an Enumerator.
|
|
3108
|
+
#
|
|
3109
|
+
def rfind: () { (E) -> boolish } -> E?
|
|
3110
|
+
| () -> Enumerator[E, E?]
|
|
3111
|
+
| [T] (Enumerable::_NotFound[T]? ifnone) { (E) -> boolish } -> (E | T)
|
|
3112
|
+
| [T] (Enumerable::_NotFound[T]? ifnone) -> Enumerator[E, E | T]
|
|
2991
3113
|
|
|
2992
3114
|
# <!--
|
|
2993
3115
|
# rdoc-file=array.c
|
|
@@ -2995,7 +3117,8 @@ class Array[unchecked out Elem] < Object
|
|
|
2995
3117
|
# - rindex {|element| ... } -> integer or nil
|
|
2996
3118
|
# - rindex -> new_enumerator
|
|
2997
3119
|
# -->
|
|
2998
|
-
# Returns the index of the last element for which
|
|
3120
|
+
# Returns the index of the last element for which <code>object ==
|
|
3121
|
+
# element</code>.
|
|
2999
3122
|
#
|
|
3000
3123
|
# With argument `object` given, returns the index of the last such element
|
|
3001
3124
|
# found:
|
|
@@ -3017,9 +3140,9 @@ class Array[unchecked out Elem] < Object
|
|
|
3017
3140
|
#
|
|
3018
3141
|
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
|
|
3019
3142
|
#
|
|
3020
|
-
def rindex: (untyped
|
|
3021
|
-
| () { (
|
|
3022
|
-
| () ->
|
|
3143
|
+
def rindex: (untyped object) -> Integer? # where E: _Equal
|
|
3144
|
+
| () { (E element) -> boolish } -> Integer?
|
|
3145
|
+
| () -> Enumerator[E, Integer?]
|
|
3023
3146
|
|
|
3024
3147
|
# <!--
|
|
3025
3148
|
# rdoc-file=array.c
|
|
@@ -3034,7 +3157,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3034
3157
|
# [0, 1, 2, 3].rotate(2) # => [2, 3, 0, 1]
|
|
3035
3158
|
# [0, 1, 2, 3].rotate(2.1) # => [2, 3, 0, 1]
|
|
3036
3159
|
#
|
|
3037
|
-
# If `count` is large, uses
|
|
3160
|
+
# If `count` is large, uses <code>count % array.size</code> as the count:
|
|
3038
3161
|
#
|
|
3039
3162
|
# [0, 1, 2, 3].rotate(22) # => [2, 3, 0, 1]
|
|
3040
3163
|
#
|
|
@@ -3047,13 +3170,14 @@ class Array[unchecked out Elem] < Object
|
|
|
3047
3170
|
#
|
|
3048
3171
|
# [0, 1, 2, 3].rotate(-1) # => [3, 0, 1, 2]
|
|
3049
3172
|
#
|
|
3050
|
-
# If `count` is small (far from zero), uses
|
|
3173
|
+
# If `count` is small (far from zero), uses <code>count % array.size</code> as
|
|
3174
|
+
# the count:
|
|
3051
3175
|
#
|
|
3052
3176
|
# [0, 1, 2, 3].rotate(-21) # => [3, 0, 1, 2]
|
|
3053
3177
|
#
|
|
3054
3178
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3055
3179
|
#
|
|
3056
|
-
def rotate: (?int count) ->
|
|
3180
|
+
def rotate: (?int count) -> Array[E]
|
|
3057
3181
|
|
|
3058
3182
|
# <!--
|
|
3059
3183
|
# rdoc-file=array.c
|
|
@@ -3068,7 +3192,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3068
3192
|
# [0, 1, 2, 3].rotate!(2) # => [2, 3, 0, 1]
|
|
3069
3193
|
# [0, 1, 2, 3].rotate!(2.1) # => [2, 3, 0, 1]
|
|
3070
3194
|
#
|
|
3071
|
-
# If `count` is large, uses
|
|
3195
|
+
# If `count` is large, uses <code>count % array.size</code> as the count:
|
|
3072
3196
|
#
|
|
3073
3197
|
# [0, 1, 2, 3].rotate!(21) # => [1, 2, 3, 0]
|
|
3074
3198
|
#
|
|
@@ -3081,7 +3205,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3081
3205
|
#
|
|
3082
3206
|
# [0, 1, 2, 3].rotate!(-1) # => [3, 0, 1, 2]
|
|
3083
3207
|
#
|
|
3084
|
-
# If `count` is small (far from zero), uses
|
|
3208
|
+
# If `count` is small (far from zero), uses <code>count % array.size</code> as
|
|
3209
|
+
# the count:
|
|
3085
3210
|
#
|
|
3086
3211
|
# [0, 1, 2, 3].rotate!(-21) # => [3, 0, 1, 2]
|
|
3087
3212
|
#
|
|
@@ -3115,7 +3240,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3115
3240
|
#
|
|
3116
3241
|
# The order of the result array is unrelated to the order of `self`.
|
|
3117
3242
|
#
|
|
3118
|
-
# Returns a new empty
|
|
3243
|
+
# Returns a new empty array if `self` is empty:
|
|
3119
3244
|
#
|
|
3120
3245
|
# [].sample(4) # => []
|
|
3121
3246
|
#
|
|
@@ -3124,8 +3249,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3124
3249
|
# a = [1, 1, 1, 2, 2, 3]
|
|
3125
3250
|
# a.sample(a.size) # => [1, 1, 3, 2, 1, 2]
|
|
3126
3251
|
#
|
|
3127
|
-
# Returns no more than
|
|
3128
|
-
# introduced):
|
|
3252
|
+
# Returns no more than <code>a.size</code> elements (because no new duplicates
|
|
3253
|
+
# are introduced):
|
|
3129
3254
|
#
|
|
3130
3255
|
# a.sample(50) # => [6, 4, 1, 8, 5, 9, 0, 2, 3, 7]
|
|
3131
3256
|
#
|
|
@@ -3138,8 +3263,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3138
3263
|
#
|
|
3139
3264
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3140
3265
|
#
|
|
3141
|
-
def sample: %a{implicitly-returns-nil} (?random: _Rand
|
|
3142
|
-
| (int
|
|
3266
|
+
def sample: %a{implicitly-returns-nil} (?random: _Rand) -> E
|
|
3267
|
+
| (int count, ?random: _Rand) -> Array[E]
|
|
3143
3268
|
|
|
3144
3269
|
# <!--
|
|
3145
3270
|
# rdoc-file=array.c
|
|
@@ -3160,8 +3285,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3160
3285
|
#
|
|
3161
3286
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3162
3287
|
#
|
|
3163
|
-
def select: () { (
|
|
3164
|
-
| () ->
|
|
3288
|
+
def select: () { (E element) -> boolish } -> Array[E]
|
|
3289
|
+
| () -> Enumerator[E, Array[E]]
|
|
3165
3290
|
|
|
3166
3291
|
# <!--
|
|
3167
3292
|
# rdoc-file=array.c
|
|
@@ -3184,8 +3309,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3184
3309
|
#
|
|
3185
3310
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
3186
3311
|
#
|
|
3187
|
-
def select!: () { (
|
|
3188
|
-
| () ->
|
|
3312
|
+
def select!: () { (E element) -> boolish } -> self?
|
|
3313
|
+
| () -> Enumerator[E, self?]
|
|
3189
3314
|
|
|
3190
3315
|
# <!--
|
|
3191
3316
|
# rdoc-file=array.c
|
|
@@ -3223,8 +3348,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3223
3348
|
#
|
|
3224
3349
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
3225
3350
|
#
|
|
3226
|
-
def shift: %a{implicitly-returns-nil} () ->
|
|
3227
|
-
| (int
|
|
3351
|
+
def shift: %a{implicitly-returns-nil} () -> E
|
|
3352
|
+
| (int count) -> Array[E]
|
|
3228
3353
|
|
|
3229
3354
|
# <!--
|
|
3230
3355
|
# rdoc-file=array.rb
|
|
@@ -3248,7 +3373,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3248
3373
|
#
|
|
3249
3374
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3250
3375
|
#
|
|
3251
|
-
def shuffle: (?random: _Rand
|
|
3376
|
+
def shuffle: (?random: _Rand) -> Array[E]
|
|
3252
3377
|
|
|
3253
3378
|
# <!--
|
|
3254
3379
|
# rdoc-file=array.rb
|
|
@@ -3272,7 +3397,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3272
3397
|
#
|
|
3273
3398
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
3274
3399
|
#
|
|
3275
|
-
def shuffle!: (?random: _Rand
|
|
3400
|
+
def shuffle!: (?random: _Rand) -> self
|
|
3276
3401
|
|
|
3277
3402
|
# <!-- rdoc-file=array.c -->
|
|
3278
3403
|
# Returns the count of elements in `self`:
|
|
@@ -3320,50 +3445,52 @@ class Array[unchecked out Elem] < Object
|
|
|
3320
3445
|
#
|
|
3321
3446
|
# If `index` is out of range, returns `nil`.
|
|
3322
3447
|
#
|
|
3323
|
-
# When two Integer arguments `start` and `length` are given, returns a new
|
|
3324
|
-
#
|
|
3325
|
-
# `start`:
|
|
3448
|
+
# When two Integer arguments `start` and `length` are given, returns a new array
|
|
3449
|
+
# of size `length` containing successive elements beginning at offset `start`:
|
|
3326
3450
|
#
|
|
3327
3451
|
# a = [:foo, 'bar', 2]
|
|
3328
3452
|
# a[0, 2] # => [:foo, "bar"]
|
|
3329
3453
|
# a[1, 2] # => ["bar", 2]
|
|
3330
3454
|
#
|
|
3331
|
-
# If
|
|
3332
|
-
# offset `start` to the end:
|
|
3455
|
+
# If <code>start + length</code> is greater than <code>self.length</code>,
|
|
3456
|
+
# returns all elements from offset `start` to the end:
|
|
3333
3457
|
#
|
|
3334
3458
|
# a = [:foo, 'bar', 2]
|
|
3335
3459
|
# a[0, 4] # => [:foo, "bar", 2]
|
|
3336
3460
|
# a[1, 3] # => ["bar", 2]
|
|
3337
3461
|
# a[2, 2] # => [2]
|
|
3338
3462
|
#
|
|
3339
|
-
# If
|
|
3463
|
+
# If <code>start == self.size</code> and <code>length >= 0</code>, returns a new
|
|
3464
|
+
# empty array.
|
|
3340
3465
|
#
|
|
3341
3466
|
# If `length` is negative, returns `nil`.
|
|
3342
3467
|
#
|
|
3343
|
-
# When a single Range argument `range` is given, treats
|
|
3344
|
-
# above and
|
|
3468
|
+
# When a single Range argument `range` is given, treats <code>range.min</code>
|
|
3469
|
+
# as `start` above and <code>range.size</code> as `length` above:
|
|
3345
3470
|
#
|
|
3346
3471
|
# a = [:foo, 'bar', 2]
|
|
3347
3472
|
# a[0..1] # => [:foo, "bar"]
|
|
3348
3473
|
# a[1..2] # => ["bar", 2]
|
|
3349
3474
|
#
|
|
3350
|
-
# Special case: If
|
|
3475
|
+
# Special case: If <code>range.start == a.size</code>, returns a new empty
|
|
3476
|
+
# array.
|
|
3351
3477
|
#
|
|
3352
|
-
# If
|
|
3478
|
+
# If <code>range.end</code> is negative, calculates the end index from the end:
|
|
3353
3479
|
#
|
|
3354
3480
|
# a = [:foo, 'bar', 2]
|
|
3355
3481
|
# a[0..-1] # => [:foo, "bar", 2]
|
|
3356
3482
|
# a[0..-2] # => [:foo, "bar"]
|
|
3357
3483
|
# a[0..-3] # => [:foo]
|
|
3358
3484
|
#
|
|
3359
|
-
# If
|
|
3485
|
+
# If <code>range.start</code> is negative, calculates the start index from the
|
|
3486
|
+
# end:
|
|
3360
3487
|
#
|
|
3361
3488
|
# a = [:foo, 'bar', 2]
|
|
3362
3489
|
# a[-1..2] # => [2]
|
|
3363
3490
|
# a[-2..2] # => ["bar", 2]
|
|
3364
3491
|
# a[-3..2] # => [:foo, "bar", 2]
|
|
3365
3492
|
#
|
|
3366
|
-
# If
|
|
3493
|
+
# If <code>range.start</code> is larger than the array size, returns `nil`.
|
|
3367
3494
|
#
|
|
3368
3495
|
# a = [:foo, 'bar', 2]
|
|
3369
3496
|
# a[4..1] # => nil
|
|
@@ -3371,7 +3498,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3371
3498
|
# a[4..-1] # => nil
|
|
3372
3499
|
#
|
|
3373
3500
|
# When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
|
|
3374
|
-
# an
|
|
3501
|
+
# an array of elements corresponding to the indexes produced by the sequence.
|
|
3375
3502
|
#
|
|
3376
3503
|
# a = ['--', 'data1', '--', 'data2', '--', 'data3']
|
|
3377
3504
|
# a[(1..).step(2)] # => ["data1", "data2", "data3"]
|
|
@@ -3394,9 +3521,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3394
3521
|
#
|
|
3395
3522
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3396
3523
|
#
|
|
3397
|
-
|
|
3398
|
-
| (int start, int length) -> ::Array[Elem]?
|
|
3399
|
-
| (::Range[::Integer] range) -> ::Array[Elem]?
|
|
3524
|
+
alias slice []
|
|
3400
3525
|
|
|
3401
3526
|
# <!--
|
|
3402
3527
|
# rdoc-file=array.c
|
|
@@ -3445,51 +3570,52 @@ class Array[unchecked out Elem] < Object
|
|
|
3445
3570
|
# a.slice!(5, 1) # => nil
|
|
3446
3571
|
# a.slice!(-5, 1) # => nil
|
|
3447
3572
|
#
|
|
3448
|
-
# If
|
|
3449
|
-
# from offset `start` to the end:
|
|
3573
|
+
# If <code>start + length</code> exceeds the array size, removes and returns all
|
|
3574
|
+
# elements from offset `start` to the end:
|
|
3450
3575
|
#
|
|
3451
3576
|
# a = ['a', 'b', 'c', 'd']
|
|
3452
3577
|
# a.slice!(2, 50) # => ["c", "d"]
|
|
3453
3578
|
# a # => ["a", "b"]
|
|
3454
3579
|
#
|
|
3455
|
-
# If
|
|
3580
|
+
# If <code>start == a.size</code> and `length` is non-negative, returns a new
|
|
3581
|
+
# empty array.
|
|
3456
3582
|
#
|
|
3457
3583
|
# If `length` is negative, returns `nil`.
|
|
3458
3584
|
#
|
|
3459
|
-
# With Range argument `range` given, treats
|
|
3460
|
-
# and
|
|
3585
|
+
# With Range argument `range` given, treats <code>range.min</code> as `start`
|
|
3586
|
+
# (as above) and <code>range.size</code> as `length` (as above):
|
|
3461
3587
|
#
|
|
3462
3588
|
# a = ['a', 'b', 'c', 'd']
|
|
3463
3589
|
# a.slice!(1..2) # => ["b", "c"]
|
|
3464
3590
|
# a # => ["a", "d"]
|
|
3465
3591
|
#
|
|
3466
|
-
# If
|
|
3592
|
+
# If <code>range.start == a.size</code>, returns a new empty array:
|
|
3467
3593
|
#
|
|
3468
3594
|
# a = ['a', 'b', 'c', 'd']
|
|
3469
3595
|
# a.slice!(4..5) # => []
|
|
3470
3596
|
#
|
|
3471
|
-
# If
|
|
3597
|
+
# If <code>range.start</code> is larger than the array size, returns `nil`:
|
|
3472
3598
|
#
|
|
3473
3599
|
# a = ['a', 'b', 'c', 'd']
|
|
3474
3600
|
# a.slice!(5..6) # => nil
|
|
3475
3601
|
#
|
|
3476
|
-
# If
|
|
3477
|
-
# from the end of `self`:
|
|
3602
|
+
# If <code>range.start</code> is negative, calculates the start index by
|
|
3603
|
+
# counting backwards from the end of `self`:
|
|
3478
3604
|
#
|
|
3479
3605
|
# a = ['a', 'b', 'c', 'd']
|
|
3480
3606
|
# a.slice!(-2..2) # => ["c"]
|
|
3481
3607
|
#
|
|
3482
|
-
# If
|
|
3483
|
-
# from the end of `self`:
|
|
3608
|
+
# If <code>range.end</code> is negative, calculates the end index by counting
|
|
3609
|
+
# backwards from the end of `self`:
|
|
3484
3610
|
#
|
|
3485
3611
|
# a = ['a', 'b', 'c', 'd']
|
|
3486
3612
|
# a.slice!(0..-2) # => ["a", "b", "c"]
|
|
3487
3613
|
#
|
|
3488
3614
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
3489
3615
|
#
|
|
3490
|
-
def slice!: %a{implicitly-returns-nil} (int index) ->
|
|
3491
|
-
| (int start, int length) ->
|
|
3492
|
-
| (
|
|
3616
|
+
def slice!: %a{implicitly-returns-nil} (int index) -> E
|
|
3617
|
+
| (int start, int length) -> Array[E]?
|
|
3618
|
+
| (range[int?] range) -> Array[E]?
|
|
3493
3619
|
|
|
3494
3620
|
# <!--
|
|
3495
3621
|
# rdoc-file=array.c
|
|
@@ -3498,7 +3624,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3498
3624
|
# -->
|
|
3499
3625
|
# Returns a new array containing the elements of `self`, sorted.
|
|
3500
3626
|
#
|
|
3501
|
-
# With no block given, compares elements using operator
|
|
3627
|
+
# With no block given, compares elements using operator <code>#<=></code> (see
|
|
3628
|
+
# Object#<=>):
|
|
3502
3629
|
#
|
|
3503
3630
|
# [0, 2, 3, 1].sort # => [0, 1, 2, 3]
|
|
3504
3631
|
#
|
|
@@ -3518,10 +3645,14 @@ class Array[unchecked out Elem] < Object
|
|
|
3518
3645
|
# When the block returns zero, the order for `a` and `b` is indeterminate, and
|
|
3519
3646
|
# may be unstable.
|
|
3520
3647
|
#
|
|
3648
|
+
# See an example in Numeric#nonzero? for the idiom to sort more complex
|
|
3649
|
+
# structure.
|
|
3650
|
+
#
|
|
3521
3651
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3522
3652
|
#
|
|
3523
|
-
def sort: () ->
|
|
3524
|
-
| () { (
|
|
3653
|
+
def sort: () -> Array[E] # where E: Comparable::_WithSpaceshipOperator
|
|
3654
|
+
| () { (E a, E b) -> Comparable::_CompareToZero } -> Array[E]
|
|
3655
|
+
| %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> Array[E]
|
|
3525
3656
|
|
|
3526
3657
|
# <!--
|
|
3527
3658
|
# rdoc-file=array.c
|
|
@@ -3532,8 +3663,9 @@ class Array[unchecked out Elem] < Object
|
|
|
3532
3663
|
#
|
|
3533
3664
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
3534
3665
|
#
|
|
3535
|
-
def sort!: () -> self
|
|
3536
|
-
| () { (
|
|
3666
|
+
def sort!: () -> self # where E: Comparable::_WithSpaceshipOperator
|
|
3667
|
+
| () { (E a, E b) -> Comparable::_CompareToZero } -> self
|
|
3668
|
+
| %a{warning: returning `nil` will always raise at runtime} () { (E a, E b) -> Comparable::_CompareToZero? } -> self
|
|
3537
3669
|
|
|
3538
3670
|
# <!--
|
|
3539
3671
|
# rdoc-file=array.c
|
|
@@ -3556,8 +3688,9 @@ class Array[unchecked out Elem] < Object
|
|
|
3556
3688
|
#
|
|
3557
3689
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
3558
3690
|
#
|
|
3559
|
-
def sort_by!:
|
|
3560
|
-
| () -> ::
|
|
3691
|
+
def sort_by!: () { (E element) -> Comparable::_WithSpaceshipOperator } -> self
|
|
3692
|
+
| %a{warning: returning `nil` will always raise at runtime} () { (E element) -> Comparable::_WithSpaceshipOperator? } -> self
|
|
3693
|
+
| () -> Enumerator[E, self]
|
|
3561
3694
|
|
|
3562
3695
|
# <!--
|
|
3563
3696
|
# rdoc-file=array.c
|
|
@@ -3571,7 +3704,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3571
3704
|
# array.each {|element| sum += element }
|
|
3572
3705
|
# sum
|
|
3573
3706
|
#
|
|
3574
|
-
# For example,
|
|
3707
|
+
# For example, <code>[e0, e1, e2].sum</code> returns <code>init + e0 + e1 +
|
|
3708
|
+
# e2</code>.
|
|
3575
3709
|
#
|
|
3576
3710
|
# Examples:
|
|
3577
3711
|
#
|
|
@@ -3582,7 +3716,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3582
3716
|
# # => [2, 3, :foo, :bar, "foo", "bar"]
|
|
3583
3717
|
#
|
|
3584
3718
|
# The `init` value and elements need not be numeric, but must all be
|
|
3585
|
-
#
|
|
3719
|
+
# <code>+</code>-compatible:
|
|
3586
3720
|
#
|
|
3587
3721
|
# # Raises TypeError: Array can't be coerced into Integer.
|
|
3588
3722
|
# [[:foo, :bar], ['foo', 'bar']].sum(2)
|
|
@@ -3600,8 +3734,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3600
3734
|
# * Array#sum method may not respect method redefinition of "+" methods such
|
|
3601
3735
|
# as Integer#+.
|
|
3602
3736
|
#
|
|
3603
|
-
def sum: (?untyped init) -> untyped
|
|
3604
|
-
| (?untyped init) { (Elem e) -> untyped } -> untyped
|
|
3737
|
+
def sum: (?untyped init) ?{ (E e) -> untyped } -> untyped # This would be usable if we had `where E < Complex`, etc
|
|
3605
3738
|
|
|
3606
3739
|
# <!--
|
|
3607
3740
|
# rdoc-file=array.c
|
|
@@ -3618,7 +3751,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3618
3751
|
#
|
|
3619
3752
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3620
3753
|
#
|
|
3621
|
-
def take: (int
|
|
3754
|
+
def take: (int count) -> Array[E]
|
|
3622
3755
|
|
|
3623
3756
|
# <!--
|
|
3624
3757
|
# rdoc-file=array.c
|
|
@@ -3640,14 +3773,14 @@ class Array[unchecked out Elem] < Object
|
|
|
3640
3773
|
#
|
|
3641
3774
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3642
3775
|
#
|
|
3643
|
-
def take_while: () { (
|
|
3644
|
-
| () ->
|
|
3776
|
+
def take_while: () { (E element) -> boolish } -> Array[E]
|
|
3777
|
+
| () -> Enumerator[E, Array[E]]
|
|
3645
3778
|
|
|
3646
3779
|
# <!--
|
|
3647
3780
|
# rdoc-file=array.c
|
|
3648
3781
|
# - to_a -> self or new_array
|
|
3649
3782
|
# -->
|
|
3650
|
-
# When `self` is an instance of
|
|
3783
|
+
# When `self` is an instance of Array, returns `self`.
|
|
3651
3784
|
#
|
|
3652
3785
|
# Otherwise, returns a new array containing the elements of `self`:
|
|
3653
3786
|
#
|
|
@@ -3659,11 +3792,11 @@ class Array[unchecked out Elem] < Object
|
|
|
3659
3792
|
#
|
|
3660
3793
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
3661
3794
|
#
|
|
3662
|
-
def to_a: () ->
|
|
3795
|
+
def to_a: () -> Array[E]
|
|
3663
3796
|
|
|
3664
3797
|
# <!--
|
|
3665
3798
|
# rdoc-file=array.c
|
|
3666
|
-
# -
|
|
3799
|
+
# - to_ary -> self
|
|
3667
3800
|
# -->
|
|
3668
3801
|
# Returns `self`.
|
|
3669
3802
|
#
|
|
@@ -3694,11 +3827,11 @@ class Array[unchecked out Elem] < Object
|
|
|
3694
3827
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
3695
3828
|
#
|
|
3696
3829
|
def to_h: () -> Hash[untyped, untyped]
|
|
3697
|
-
| [
|
|
3830
|
+
| [K, V] () { (E element) -> Hash::_Pair[K, V] } -> Hash[K, V]
|
|
3698
3831
|
|
|
3699
3832
|
# <!-- rdoc-file=array.c -->
|
|
3700
|
-
# Returns the new string formed by calling method
|
|
3701
|
-
# element:
|
|
3833
|
+
# Returns the new string formed by calling method <code>#inspect</code> on each
|
|
3834
|
+
# array element:
|
|
3702
3835
|
#
|
|
3703
3836
|
# a = [:foo, 'bar', 2]
|
|
3704
3837
|
# a.inspect # => "[:foo, \"bar\", 2]"
|
|
@@ -3721,14 +3854,14 @@ class Array[unchecked out Elem] < Object
|
|
|
3721
3854
|
#
|
|
3722
3855
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
3723
3856
|
#
|
|
3724
|
-
def transpose: () ->
|
|
3857
|
+
def transpose: () -> Array[Array[untyped]]
|
|
3725
3858
|
|
|
3726
3859
|
# <!--
|
|
3727
3860
|
# rdoc-file=array.c
|
|
3728
3861
|
# - union(*other_arrays) -> new_array
|
|
3729
3862
|
# -->
|
|
3730
3863
|
# Returns a new array that is the union of the elements of `self` and all given
|
|
3731
|
-
# arrays `other_arrays`; items are compared using
|
|
3864
|
+
# arrays `other_arrays`; items are compared using <code>eql?</code>:
|
|
3732
3865
|
#
|
|
3733
3866
|
# [0, 1, 2, 3].union([4, 5], [6, 7]) # => [0, 1, 2, 3, 4, 5, 6, 7]
|
|
3734
3867
|
#
|
|
@@ -3744,7 +3877,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3744
3877
|
#
|
|
3745
3878
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
3746
3879
|
#
|
|
3747
|
-
def union: [T] (
|
|
3880
|
+
def union: [T] (*array[T] other_arrays) -> Array[T | E] # where E: _Eql?[T]
|
|
3748
3881
|
|
|
3749
3882
|
# <!--
|
|
3750
3883
|
# rdoc-file=array.c
|
|
@@ -3755,23 +3888,23 @@ class Array[unchecked out Elem] < Object
|
|
|
3755
3888
|
# duplicates, the first occurrence always being retained.
|
|
3756
3889
|
#
|
|
3757
3890
|
# With no block given, identifies and omits duplicate elements using method
|
|
3758
|
-
#
|
|
3891
|
+
# <code>eql?</code> to compare elements:
|
|
3759
3892
|
#
|
|
3760
3893
|
# a = [0, 0, 1, 1, 2, 2]
|
|
3761
3894
|
# a.uniq # => [0, 1, 2]
|
|
3762
3895
|
#
|
|
3763
3896
|
# With a block given, calls the block for each element; identifies and omits
|
|
3764
|
-
# "duplicate" elements using method
|
|
3765
|
-
# that is, an element is a duplicate if its block return value is the
|
|
3766
|
-
# that of a previous element:
|
|
3897
|
+
# "duplicate" elements using method <code>eql?</code> to compare *block return
|
|
3898
|
+
# values*; that is, an element is a duplicate if its block return value is the
|
|
3899
|
+
# same as that of a previous element:
|
|
3767
3900
|
#
|
|
3768
3901
|
# a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
|
|
3769
3902
|
# a.uniq {|element| element.size } # => ["a", "aa", "aaa"]
|
|
3770
3903
|
#
|
|
3771
3904
|
# Related: [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3772
3905
|
#
|
|
3773
|
-
def uniq: () ->
|
|
3774
|
-
| () { (
|
|
3906
|
+
def uniq: () -> Array[E] # where E: Hash::_Key
|
|
3907
|
+
| () { (E element) -> Hash::_Key } -> Array[E]
|
|
3775
3908
|
|
|
3776
3909
|
# <!--
|
|
3777
3910
|
# rdoc-file=array.c
|
|
@@ -3781,17 +3914,17 @@ class Array[unchecked out Elem] < Object
|
|
|
3781
3914
|
# Removes duplicate elements from `self`, the first occurrence always being
|
|
3782
3915
|
# retained; returns `self` if any elements removed, `nil` otherwise.
|
|
3783
3916
|
#
|
|
3784
|
-
# With no block given, identifies and removes elements using method
|
|
3785
|
-
# compare elements:
|
|
3917
|
+
# With no block given, identifies and removes elements using method
|
|
3918
|
+
# <code>eql?</code> to compare elements:
|
|
3786
3919
|
#
|
|
3787
3920
|
# a = [0, 0, 1, 1, 2, 2]
|
|
3788
3921
|
# a.uniq! # => [0, 1, 2]
|
|
3789
3922
|
# a.uniq! # => nil
|
|
3790
3923
|
#
|
|
3791
3924
|
# With a block given, calls the block for each element; identifies and omits
|
|
3792
|
-
# "duplicate" elements using method
|
|
3793
|
-
# that is, an element is a duplicate if its block return value is the
|
|
3794
|
-
# that of a previous element:
|
|
3925
|
+
# "duplicate" elements using method <code>eql?</code> to compare *block return
|
|
3926
|
+
# values*; that is, an element is a duplicate if its block return value is the
|
|
3927
|
+
# same as that of a previous element:
|
|
3795
3928
|
#
|
|
3796
3929
|
# a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
|
|
3797
3930
|
# a.uniq! {|element| element.size } # => ["a", "aa", "aaa"]
|
|
@@ -3799,8 +3932,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3799
3932
|
#
|
|
3800
3933
|
# Related: see [Methods for Deleting](rdoc-ref:Array@Methods+for+Deleting).
|
|
3801
3934
|
#
|
|
3802
|
-
def uniq!: () -> self?
|
|
3803
|
-
| () { (
|
|
3935
|
+
def uniq!: () -> self? # where E: Hash::_Key
|
|
3936
|
+
| () { (E element) -> Hash::_Key } -> self?
|
|
3804
3937
|
|
|
3805
3938
|
# <!--
|
|
3806
3939
|
# rdoc-file=array.c
|
|
@@ -3815,7 +3948,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3815
3948
|
# Related: Array#shift; see also [Methods for
|
|
3816
3949
|
# Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
3817
3950
|
#
|
|
3818
|
-
def unshift: (*
|
|
3951
|
+
def unshift: (*E objects) -> self
|
|
3819
3952
|
|
|
3820
3953
|
# <!--
|
|
3821
3954
|
# rdoc-file=array.c
|
|
@@ -3857,13 +3990,13 @@ class Array[unchecked out Elem] < Object
|
|
|
3857
3990
|
# For each numeric specifier `index`, includes an element:
|
|
3858
3991
|
#
|
|
3859
3992
|
# * For each non-negative numeric specifier `index` that is in-range (less
|
|
3860
|
-
# than
|
|
3993
|
+
# than <code>self.size</code>), includes the element at offset `index`:
|
|
3861
3994
|
#
|
|
3862
3995
|
# a.values_at(0, 2) # => ["a", "c"]
|
|
3863
3996
|
# a.values_at(0.1, 2.9) # => ["a", "c"]
|
|
3864
3997
|
#
|
|
3865
3998
|
# * For each negative numeric `index` that is in-range (greater than or equal
|
|
3866
|
-
# to
|
|
3999
|
+
# to <code>- self.size</code>), counts backwards from the end of `self`:
|
|
3867
4000
|
#
|
|
3868
4001
|
# a.values_at(-1, -4) # => ["d", "a"]
|
|
3869
4002
|
#
|
|
@@ -3875,37 +4008,41 @@ class Array[unchecked out Elem] < Object
|
|
|
3875
4008
|
#
|
|
3876
4009
|
# a.values_at(4, -5) # => [nil, nil]
|
|
3877
4010
|
#
|
|
3878
|
-
# For each Range specifier `range`, includes elements according to
|
|
3879
|
-
# and
|
|
4011
|
+
# For each Range specifier `range`, includes elements according to
|
|
4012
|
+
# <code>range.begin</code> and <code>range.end</code>:
|
|
3880
4013
|
#
|
|
3881
|
-
# * If both
|
|
3882
|
-
# than
|
|
3883
|
-
#
|
|
3884
|
-
# (
|
|
4014
|
+
# * If both <code>range.begin</code> and <code>range.end</code> are
|
|
4015
|
+
# non-negative and in-range (less than <code>self.size</code>), includes
|
|
4016
|
+
# elements from index <code>range.begin</code> through <code>range.end -
|
|
4017
|
+
# 1</code> (if <code>range.exclude_end?</code>), or through
|
|
4018
|
+
# <code>range.end</code> (otherwise):
|
|
3885
4019
|
#
|
|
3886
4020
|
# a.values_at(1..2) # => ["b", "c"]
|
|
3887
4021
|
# a.values_at(1...2) # => ["b"]
|
|
3888
4022
|
#
|
|
3889
|
-
# * If
|
|
3890
|
-
# self.size
|
|
4023
|
+
# * If <code>range.begin</code> is negative and in-range (greater than or
|
|
4024
|
+
# equal to <code>- self.size</code>), counts backwards from the end of
|
|
4025
|
+
# `self`:
|
|
3891
4026
|
#
|
|
3892
4027
|
# a.values_at(-2..3) # => ["c", "d"]
|
|
3893
4028
|
#
|
|
3894
|
-
# * If
|
|
4029
|
+
# * If <code>range.begin</code> is negative and out-of-range, raises an
|
|
4030
|
+
# exception:
|
|
3895
4031
|
#
|
|
3896
4032
|
# a.values_at(-5..3) # Raises RangeError.
|
|
3897
4033
|
#
|
|
3898
|
-
# * If
|
|
3899
|
-
# with `nil` elements:
|
|
4034
|
+
# * If <code>range.end</code> is positive and out-of-range, extends the
|
|
4035
|
+
# returned array with `nil` elements:
|
|
3900
4036
|
#
|
|
3901
4037
|
# a.values_at(1..5) # => ["b", "c", "d", nil, nil]
|
|
3902
4038
|
#
|
|
3903
|
-
# * If
|
|
3904
|
-
# `self`:
|
|
4039
|
+
# * If <code>range.end</code> is negative and in-range, counts backwards from
|
|
4040
|
+
# the end of `self`:
|
|
3905
4041
|
#
|
|
3906
4042
|
# a.values_at(1..-2) # => ["b", "c"]
|
|
3907
4043
|
#
|
|
3908
|
-
# * If
|
|
4044
|
+
# * If <code>range.end</code> is negative and out-of-range, returns an empty
|
|
4045
|
+
# array:
|
|
3909
4046
|
#
|
|
3910
4047
|
# a.values_at(1..-5) # => []
|
|
3911
4048
|
#
|
|
@@ -3919,7 +4056,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3919
4056
|
#
|
|
3920
4057
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3921
4058
|
#
|
|
3922
|
-
def values_at: (*int |
|
|
4059
|
+
def values_at: (*int | range[int?] selector) -> Array[E?]
|
|
3923
4060
|
|
|
3924
4061
|
# <!--
|
|
3925
4062
|
# rdoc-file=array.c
|
|
@@ -3934,8 +4071,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3934
4071
|
#
|
|
3935
4072
|
# Returned:
|
|
3936
4073
|
#
|
|
3937
|
-
# * The outer array is of size
|
|
3938
|
-
# * Each sub-array is of size
|
|
4074
|
+
# * The outer array is of size <code>self.size</code>.
|
|
4075
|
+
# * Each sub-array is of size <code>other_arrays.size + 1</code>.
|
|
3939
4076
|
# * The *nth* sub-array contains (in order):
|
|
3940
4077
|
#
|
|
3941
4078
|
# * The *nth* element of `self`.
|
|
@@ -4008,22 +4145,26 @@ class Array[unchecked out Elem] < Object
|
|
|
4008
4145
|
# [:c3, :b3, :a3]]
|
|
4009
4146
|
#
|
|
4010
4147
|
# For an **object** in **other_arrays** that is not actually an array, forms the
|
|
4011
|
-
#
|
|
4012
|
-
# otherwise.
|
|
4148
|
+
# "other array" as <code>object.to_ary</code>, if defined, or as
|
|
4149
|
+
# <code>object.each.to_a</code> otherwise.
|
|
4013
4150
|
#
|
|
4014
4151
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
|
4015
4152
|
#
|
|
4016
|
-
def zip:
|
|
4017
|
-
|
|
|
4018
|
-
| [
|
|
4019
|
-
|
|
|
4153
|
+
def zip: () -> Array[[ E ]]
|
|
4154
|
+
| [X] (_Each[X] iterable) -> Array[[ E, X? ]]
|
|
4155
|
+
| [X, Y] (_Each[X] iterable1, _Each[Y] iterable2) -> Array[[ E, X?, Y? ]]
|
|
4156
|
+
| [U] (*_Each[U] iterables) -> Array[Array[E | U?]]
|
|
4157
|
+
| () { ([ E ]) -> void } -> nil
|
|
4158
|
+
| [X] (_Each[X] iterable) { ([ E, X? ]) -> void } -> nil
|
|
4159
|
+
| [X, Y] (_Each[X] iterable1, _Each[Y] iterable2) { ([ E, X?, Y? ]) -> void } -> nil
|
|
4160
|
+
| [U] (*_Each[U] iterables) { (Array[E | U?]) -> void } -> nil
|
|
4020
4161
|
|
|
4021
4162
|
# <!--
|
|
4022
4163
|
# rdoc-file=array.c
|
|
4023
4164
|
# - self | other_array -> new_array
|
|
4024
4165
|
# -->
|
|
4025
4166
|
# Returns the union of `self` and `other_array`; duplicates are removed; order
|
|
4026
|
-
# is preserved; items are compared using
|
|
4167
|
+
# is preserved; items are compared using <code>eql?</code>:
|
|
4027
4168
|
#
|
|
4028
4169
|
# [0, 1] | [2, 3] # => [0, 1, 2, 3]
|
|
4029
4170
|
# [0, 1, 1] | [2, 2, 3] # => [0, 1, 2, 3]
|
|
@@ -4031,7 +4172,7 @@ class Array[unchecked out Elem] < Object
|
|
|
4031
4172
|
#
|
|
4032
4173
|
# Related: see [Methods for Combining](rdoc-ref:Array@Methods+for+Combining).
|
|
4033
4174
|
#
|
|
4034
|
-
def |: [T] (
|
|
4175
|
+
def |: [T] (array[T] other_array) -> Array[E | T] # where E: _Eql?[T]
|
|
4035
4176
|
|
|
4036
4177
|
private
|
|
4037
4178
|
|
|
@@ -4050,13 +4191,15 @@ class Array[unchecked out Elem] < Object
|
|
|
4050
4191
|
#
|
|
4051
4192
|
# Related: see [Methods for Assigning](rdoc-ref:Array@Methods+for+Assigning).
|
|
4052
4193
|
#
|
|
4053
|
-
|
|
4194
|
+
alias initialize_copy replace
|
|
4054
4195
|
end
|
|
4055
4196
|
|
|
4197
|
+
%a{deprecated: Use Array::_Rand, or make your own}
|
|
4056
4198
|
interface _Rand
|
|
4057
|
-
def rand: (
|
|
4199
|
+
def rand: (Integer max) -> Integer
|
|
4058
4200
|
end
|
|
4059
4201
|
|
|
4202
|
+
%a{deprecated: Use RBS::Ops::_CaseEqual[E, boolish]}
|
|
4060
4203
|
interface Array::_Pattern[T]
|
|
4061
4204
|
def ===: (T) -> bool
|
|
4062
4205
|
end
|