rbs 3.9.5 → 3.10.0
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 +74 -0
- data/.clangd +2 -0
- data/.github/workflows/c-check.yml +54 -0
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +34 -19
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/.gitignore +4 -0
- data/CHANGELOG.md +49 -0
- data/README.md +38 -1
- data/Rakefile +152 -23
- data/config.yml +190 -62
- data/core/array.rbs +100 -46
- data/core/complex.rbs +32 -21
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +6 -9
- data/core/enumerable.rbs +90 -3
- data/core/enumerator.rbs +18 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +5 -4
- data/core/file.rbs +27 -12
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +209 -22
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1024 -727
- data/core/integer.rbs +78 -38
- data/core/io/buffer.rbs +18 -7
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +14 -12
- data/core/kernel.rbs +57 -51
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +14 -6
- data/core/module.rbs +88 -17
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +16 -16
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/{stdlib/pathname/0 → core}/pathname.rbs +255 -355
- data/core/proc.rbs +15 -8
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +278 -437
- data/core/range.rbs +7 -8
- data/core/rational.rbs +37 -24
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -2
- data/core/regexp.rbs +25 -20
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +488 -359
- data/core/string.rbs +3145 -1231
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +92 -29
- data/core/time.rbs +35 -9
- data/core/trace_point.rbs +7 -4
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1016 -0
- data/ext/rbs_extension/ast_translation.h +37 -0
- data/ext/rbs_extension/class_constants.c +155 -0
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +25 -1
- data/ext/rbs_extension/legacy_location.c +317 -0
- data/ext/rbs_extension/legacy_location.h +45 -0
- data/ext/rbs_extension/main.c +357 -14
- 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 +687 -0
- data/include/rbs/defines.h +86 -0
- data/include/rbs/lexer.h +199 -0
- data/include/rbs/location.h +59 -0
- data/include/rbs/parser.h +135 -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 -67
- data/include/rbs/util/rbs_encoding.h +282 -0
- data/include/rbs/util/rbs_unescape.h +24 -0
- data/include/rbs.h +1 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/cli/validate.rb +2 -2
- data/lib/rbs/cli.rb +1 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
- data/lib/rbs/environment.rb +64 -59
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/errors.rb +1 -1
- data/lib/rbs/parser_aux.rb +5 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +124 -38
- data/lib/rbs/test/type_check.rb +14 -0
- data/lib/rbs/types.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/environment.rbs +57 -6
- data/sig/manifest.yaml +0 -1
- data/sig/parser.rbs +20 -0
- data/sig/resolver/type_name_resolver.rbs +38 -7
- data/sig/types.rbs +4 -1
- data/src/ast.c +1256 -0
- data/src/lexer.c +2956 -0
- data/src/lexer.re +147 -0
- data/src/lexstate.c +205 -0
- data/src/location.c +71 -0
- data/src/parser.c +3507 -0
- data/src/string.c +41 -0
- data/src/util/rbs_allocator.c +152 -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 -88
- data/src/util/rbs_encoding.c +21308 -0
- data/src/util/rbs_unescape.c +167 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +2 -396
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +153 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +18 -13
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +68 -48
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -4
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/rdoc/0/code_object.rbs +2 -2
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/rdoc.rbs +7 -5
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +5 -2
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +1176 -85
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +11 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +17 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +43 -18
- 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.
|
|
@@ -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`.
|
|
@@ -840,9 +840,8 @@ class Array[unchecked out Elem] < Object
|
|
|
840
840
|
#
|
|
841
841
|
# If `index` is out of range, returns `nil`.
|
|
842
842
|
#
|
|
843
|
-
# When two Integer arguments `start` and `length` are given, returns a new
|
|
844
|
-
#
|
|
845
|
-
# `start`:
|
|
843
|
+
# When two Integer arguments `start` and `length` are given, returns a new array
|
|
844
|
+
# of size `length` containing successive elements beginning at offset `start`:
|
|
846
845
|
#
|
|
847
846
|
# a = [:foo, 'bar', 2]
|
|
848
847
|
# a[0, 2] # => [:foo, "bar"]
|
|
@@ -856,7 +855,7 @@ class Array[unchecked out Elem] < Object
|
|
|
856
855
|
# a[1, 3] # => ["bar", 2]
|
|
857
856
|
# a[2, 2] # => [2]
|
|
858
857
|
#
|
|
859
|
-
# If `start == self.size` and `length >= 0`, returns a new empty
|
|
858
|
+
# If `start == self.size` and `length >= 0`, returns a new empty array.
|
|
860
859
|
#
|
|
861
860
|
# If `length` is negative, returns `nil`.
|
|
862
861
|
#
|
|
@@ -867,7 +866,7 @@ class Array[unchecked out Elem] < Object
|
|
|
867
866
|
# a[0..1] # => [:foo, "bar"]
|
|
868
867
|
# a[1..2] # => ["bar", 2]
|
|
869
868
|
#
|
|
870
|
-
# Special case: If `range.start == a.size`, returns a new empty
|
|
869
|
+
# Special case: If `range.start == a.size`, returns a new empty array.
|
|
871
870
|
#
|
|
872
871
|
# If `range.end` is negative, calculates the end index from the end:
|
|
873
872
|
#
|
|
@@ -891,7 +890,7 @@ class Array[unchecked out Elem] < Object
|
|
|
891
890
|
# a[4..-1] # => nil
|
|
892
891
|
#
|
|
893
892
|
# When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
|
|
894
|
-
# an
|
|
893
|
+
# an array of elements corresponding to the indexes produced by the sequence.
|
|
895
894
|
#
|
|
896
895
|
# a = ['--', 'data1', '--', 'data2', '--', 'data3']
|
|
897
896
|
# a[(1..).step(2)] # => ["data1", "data2", "data3"]
|
|
@@ -976,8 +975,8 @@ class Array[unchecked out Elem] < Object
|
|
|
976
975
|
# a # => [:foo, "bar", "two"]
|
|
977
976
|
#
|
|
978
977
|
# When Integer arguments `start` and `length` are given and `object` is not an
|
|
979
|
-
#
|
|
980
|
-
#
|
|
978
|
+
# array, removes `length - 1` elements beginning at offset `start`, and assigns
|
|
979
|
+
# `object` at offset `start`:
|
|
981
980
|
#
|
|
982
981
|
# a = [:foo, 'bar', 2]
|
|
983
982
|
# a[0, 2] = 'foo' # => "foo"
|
|
@@ -1010,7 +1009,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1010
1009
|
# a[1, 5] = 'foo' # => "foo"
|
|
1011
1010
|
# a # => [:foo, "foo"]
|
|
1012
1011
|
#
|
|
1013
|
-
# When Range argument `range` is given and `object` is not an
|
|
1012
|
+
# When Range argument `range` is given and `object` is not an array, removes
|
|
1014
1013
|
# `length - 1` elements beginning at offset `start`, and assigns `object` at
|
|
1015
1014
|
# offset `start`:
|
|
1016
1015
|
#
|
|
@@ -1214,7 +1213,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1214
1213
|
# Returns the element from `self` found by a binary search, or `nil` if the
|
|
1215
1214
|
# search found no suitable element.
|
|
1216
1215
|
#
|
|
1217
|
-
# See [Binary Searching](rdoc-ref:bsearch.rdoc).
|
|
1216
|
+
# See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
|
|
1218
1217
|
#
|
|
1219
1218
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1220
1219
|
#
|
|
@@ -1230,7 +1229,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1230
1229
|
# Returns the integer index of the element from `self` found by a binary search,
|
|
1231
1230
|
# or `nil` if the search found no suitable element.
|
|
1232
1231
|
#
|
|
1233
|
-
# See [Binary Searching](rdoc-ref:bsearch.rdoc).
|
|
1232
|
+
# See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
|
|
1234
1233
|
#
|
|
1235
1234
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
1236
1235
|
#
|
|
@@ -1274,9 +1273,9 @@ class Array[unchecked out Elem] < Object
|
|
|
1274
1273
|
|
|
1275
1274
|
# <!--
|
|
1276
1275
|
# rdoc-file=array.c
|
|
1277
|
-
# - collect! {|element| ... } ->
|
|
1276
|
+
# - collect! {|element| ... } -> self
|
|
1278
1277
|
# - collect! -> new_enumerator
|
|
1279
|
-
# - map! {|element| ... } ->
|
|
1278
|
+
# - map! {|element| ... } -> self
|
|
1280
1279
|
# - map! -> new_enumerator
|
|
1281
1280
|
# -->
|
|
1282
1281
|
# With a block given, calls the block with each element of `self` and replaces
|
|
@@ -1564,7 +1563,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1564
1563
|
|
|
1565
1564
|
# <!--
|
|
1566
1565
|
# rdoc-file=array.c
|
|
1567
|
-
# -
|
|
1566
|
+
# - dig(index, *identifiers) -> object
|
|
1568
1567
|
# -->
|
|
1569
1568
|
# Finds and returns the object in nested object specified by `index` and
|
|
1570
1569
|
# `identifiers`; the nested objects may be instances of various classes. See
|
|
@@ -1693,7 +1692,7 @@ class Array[unchecked out Elem] < Object
|
|
|
1693
1692
|
|
|
1694
1693
|
# <!--
|
|
1695
1694
|
# rdoc-file=array.c
|
|
1696
|
-
# -
|
|
1695
|
+
# - empty? -> true or false
|
|
1697
1696
|
# -->
|
|
1698
1697
|
# Returns `true` if the count of elements in `self` is zero, `false` otherwise.
|
|
1699
1698
|
#
|
|
@@ -1804,10 +1803,10 @@ class Array[unchecked out Elem] < Object
|
|
|
1804
1803
|
|
|
1805
1804
|
# <!--
|
|
1806
1805
|
# 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| ... } ->
|
|
1806
|
+
# - fill(object, start = nil, count = nil) -> self
|
|
1807
|
+
# - fill(object, range) -> self
|
|
1808
|
+
# - fill(start = nil, count = nil) {|element| ... } -> self
|
|
1809
|
+
# - fill(range) {|element| ... } -> self
|
|
1811
1810
|
# -->
|
|
1812
1811
|
# Replaces selected elements in `self`; may add elements to `self`; always
|
|
1813
1812
|
# returns `self` (never a new array).
|
|
@@ -2020,6 +2019,32 @@ class Array[unchecked out Elem] < Object
|
|
|
2020
2019
|
def filter!: () { (Elem item) -> boolish } -> self?
|
|
2021
2020
|
| () -> ::Enumerator[Elem, self?]
|
|
2022
2021
|
|
|
2022
|
+
# <!--
|
|
2023
|
+
# rdoc-file=array.c
|
|
2024
|
+
# - find(if_none_proc = nil) {|element| ... } -> object or nil
|
|
2025
|
+
# - find(if_none_proc = nil) -> enumerator
|
|
2026
|
+
# -->
|
|
2027
|
+
# Returns the first element for which the block returns a truthy value.
|
|
2028
|
+
#
|
|
2029
|
+
# With a block given, calls the block with successive elements of the array;
|
|
2030
|
+
# returns the first element for which the block returns a truthy value:
|
|
2031
|
+
#
|
|
2032
|
+
# (0..9).find {|element| element > 2} # => 3
|
|
2033
|
+
#
|
|
2034
|
+
# If no such element is found, calls `if_none_proc` and returns its return
|
|
2035
|
+
# value.
|
|
2036
|
+
#
|
|
2037
|
+
# (0..9).find(proc {false}) {|element| element > 12} # => false
|
|
2038
|
+
# {foo: 0, bar: 1, baz: 2}.find {|key, value| key.start_with?('b') } # => [:bar, 1]
|
|
2039
|
+
# {foo: 0, bar: 1, baz: 2}.find(proc {[]}) {|key, value| key.start_with?('c') } # => []
|
|
2040
|
+
#
|
|
2041
|
+
# With no block given, returns an Enumerator.
|
|
2042
|
+
#
|
|
2043
|
+
def find: () { (Elem) -> boolish } -> Elem?
|
|
2044
|
+
| () -> ::Enumerator[Elem, Elem?]
|
|
2045
|
+
| [T] (Enumerable::_NotFound[T] ifnone) { (Elem) -> boolish } -> (Elem | T)
|
|
2046
|
+
| [T] (Enumerable::_NotFound[T] ifnone) -> ::Enumerator[Elem, Elem | T]
|
|
2047
|
+
|
|
2023
2048
|
# <!--
|
|
2024
2049
|
# rdoc-file=array.c
|
|
2025
2050
|
# - find_index(object) -> integer or nil
|
|
@@ -2300,7 +2325,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2300
2325
|
|
|
2301
2326
|
# <!--
|
|
2302
2327
|
# rdoc-file=array.c
|
|
2303
|
-
# -
|
|
2328
|
+
# - join(separator = $,) -> new_string
|
|
2304
2329
|
# -->
|
|
2305
2330
|
# Returns the new string formed by joining the converted elements of `self`; for
|
|
2306
2331
|
# each element `element`:
|
|
@@ -2619,7 +2644,7 @@ class Array[unchecked out Elem] < Object
|
|
|
2619
2644
|
# - pack(template, buffer: nil) -> string
|
|
2620
2645
|
# -->
|
|
2621
2646
|
# Formats each element in `self` into a binary string; returns that string. See
|
|
2622
|
-
# [Packed Data](rdoc-ref:packed_data.rdoc).
|
|
2647
|
+
# [Packed Data](rdoc-ref:language/packed_data.rdoc).
|
|
2623
2648
|
#
|
|
2624
2649
|
def pack: (string fmt, ?buffer: String?) -> String
|
|
2625
2650
|
|
|
@@ -2989,6 +3014,33 @@ class Array[unchecked out Elem] < Object
|
|
|
2989
3014
|
def reverse_each: () { (Elem item) -> void } -> self
|
|
2990
3015
|
| () -> ::Enumerator[Elem, self]
|
|
2991
3016
|
|
|
3017
|
+
# <!--
|
|
3018
|
+
# rdoc-file=array.c
|
|
3019
|
+
# - rfind(if_none_proc = nil) {|element| ... } -> object or nil
|
|
3020
|
+
# - rfind(if_none_proc = nil) -> enumerator
|
|
3021
|
+
# -->
|
|
3022
|
+
# Returns the last element for which the block returns a truthy value.
|
|
3023
|
+
#
|
|
3024
|
+
# With a block given, calls the block with successive elements of the array in
|
|
3025
|
+
# reverse order; returns the last element for which the block returns a truthy
|
|
3026
|
+
# value:
|
|
3027
|
+
#
|
|
3028
|
+
# (0..9).rfind {|element| element < 5} # => 4
|
|
3029
|
+
#
|
|
3030
|
+
# If no such element is found, calls `if_none_proc` and returns its return
|
|
3031
|
+
# value.
|
|
3032
|
+
#
|
|
3033
|
+
# (0..9).rfind(proc {false}) {|element| element < -2} # => false
|
|
3034
|
+
# {foo: 0, bar: 1, baz: 2}.rfind {|key, value| key.start_with?('b') } # => [:baz, 2]
|
|
3035
|
+
# {foo: 0, bar: 1, baz: 2}.rfind(proc {[]}) {|key, value| key.start_with?('c') } # => []
|
|
3036
|
+
#
|
|
3037
|
+
# With no block given, returns an Enumerator.
|
|
3038
|
+
#
|
|
3039
|
+
def rfind: () { (Elem) -> boolish } -> Elem?
|
|
3040
|
+
| () -> ::Enumerator[Elem, Elem?]
|
|
3041
|
+
| [T] (Enumerable::_NotFound[T] ifnone) { (Elem) -> boolish } -> (Elem | T)
|
|
3042
|
+
| [T] (Enumerable::_NotFound[T] ifnone) -> ::Enumerator[Elem, Elem | T]
|
|
3043
|
+
|
|
2992
3044
|
# <!--
|
|
2993
3045
|
# rdoc-file=array.c
|
|
2994
3046
|
# - rindex(object) -> integer or nil
|
|
@@ -3115,7 +3167,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3115
3167
|
#
|
|
3116
3168
|
# The order of the result array is unrelated to the order of `self`.
|
|
3117
3169
|
#
|
|
3118
|
-
# Returns a new empty
|
|
3170
|
+
# Returns a new empty array if `self` is empty:
|
|
3119
3171
|
#
|
|
3120
3172
|
# [].sample(4) # => []
|
|
3121
3173
|
#
|
|
@@ -3320,9 +3372,8 @@ class Array[unchecked out Elem] < Object
|
|
|
3320
3372
|
#
|
|
3321
3373
|
# If `index` is out of range, returns `nil`.
|
|
3322
3374
|
#
|
|
3323
|
-
# When two Integer arguments `start` and `length` are given, returns a new
|
|
3324
|
-
#
|
|
3325
|
-
# `start`:
|
|
3375
|
+
# When two Integer arguments `start` and `length` are given, returns a new array
|
|
3376
|
+
# of size `length` containing successive elements beginning at offset `start`:
|
|
3326
3377
|
#
|
|
3327
3378
|
# a = [:foo, 'bar', 2]
|
|
3328
3379
|
# a[0, 2] # => [:foo, "bar"]
|
|
@@ -3336,7 +3387,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3336
3387
|
# a[1, 3] # => ["bar", 2]
|
|
3337
3388
|
# a[2, 2] # => [2]
|
|
3338
3389
|
#
|
|
3339
|
-
# If `start == self.size` and `length >= 0`, returns a new empty
|
|
3390
|
+
# If `start == self.size` and `length >= 0`, returns a new empty array.
|
|
3340
3391
|
#
|
|
3341
3392
|
# If `length` is negative, returns `nil`.
|
|
3342
3393
|
#
|
|
@@ -3347,7 +3398,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3347
3398
|
# a[0..1] # => [:foo, "bar"]
|
|
3348
3399
|
# a[1..2] # => ["bar", 2]
|
|
3349
3400
|
#
|
|
3350
|
-
# Special case: If `range.start == a.size`, returns a new empty
|
|
3401
|
+
# Special case: If `range.start == a.size`, returns a new empty array.
|
|
3351
3402
|
#
|
|
3352
3403
|
# If `range.end` is negative, calculates the end index from the end:
|
|
3353
3404
|
#
|
|
@@ -3371,7 +3422,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3371
3422
|
# a[4..-1] # => nil
|
|
3372
3423
|
#
|
|
3373
3424
|
# When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns
|
|
3374
|
-
# an
|
|
3425
|
+
# an array of elements corresponding to the indexes produced by the sequence.
|
|
3375
3426
|
#
|
|
3376
3427
|
# a = ['--', 'data1', '--', 'data2', '--', 'data3']
|
|
3377
3428
|
# a[(1..).step(2)] # => ["data1", "data2", "data3"]
|
|
@@ -3518,6 +3569,9 @@ class Array[unchecked out Elem] < Object
|
|
|
3518
3569
|
# When the block returns zero, the order for `a` and `b` is indeterminate, and
|
|
3519
3570
|
# may be unstable.
|
|
3520
3571
|
#
|
|
3572
|
+
# See an example in Numeric#nonzero? for the idiom to sort more complex
|
|
3573
|
+
# structure.
|
|
3574
|
+
#
|
|
3521
3575
|
# Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
|
|
3522
3576
|
#
|
|
3523
3577
|
def sort: () -> ::Array[Elem]
|
|
@@ -3647,7 +3701,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3647
3701
|
# rdoc-file=array.c
|
|
3648
3702
|
# - to_a -> self or new_array
|
|
3649
3703
|
# -->
|
|
3650
|
-
# When `self` is an instance of
|
|
3704
|
+
# When `self` is an instance of Array, returns `self`.
|
|
3651
3705
|
#
|
|
3652
3706
|
# Otherwise, returns a new array containing the elements of `self`:
|
|
3653
3707
|
#
|
|
@@ -3663,7 +3717,7 @@ class Array[unchecked out Elem] < Object
|
|
|
3663
3717
|
|
|
3664
3718
|
# <!--
|
|
3665
3719
|
# rdoc-file=array.c
|
|
3666
|
-
# -
|
|
3720
|
+
# - to_ary -> self
|
|
3667
3721
|
# -->
|
|
3668
3722
|
# Returns `self`.
|
|
3669
3723
|
#
|
|
@@ -4008,7 +4062,7 @@ class Array[unchecked out Elem] < Object
|
|
|
4008
4062
|
# [:c3, :b3, :a3]]
|
|
4009
4063
|
#
|
|
4010
4064
|
# For an **object** in **other_arrays** that is not actually an array, forms the
|
|
4011
|
-
#
|
|
4065
|
+
# "other array" as `object.to_ary`, if defined, or as `object.each.to_a`
|
|
4012
4066
|
# otherwise.
|
|
4013
4067
|
#
|
|
4014
4068
|
# Related: see [Methods for Converting](rdoc-ref:Array@Methods+for+Converting).
|
data/core/complex.rbs
CHANGED
|
@@ -184,23 +184,24 @@ class Complex < Numeric
|
|
|
184
184
|
|
|
185
185
|
# <!--
|
|
186
186
|
# rdoc-file=complex.c
|
|
187
|
-
# -
|
|
187
|
+
# - self * other -> numeric
|
|
188
188
|
# -->
|
|
189
|
-
# Returns the product of `self` and `
|
|
189
|
+
# Returns the numeric product of `self` and `other`:
|
|
190
190
|
#
|
|
191
|
+
# Complex.rect(9, 8) * 4 # => (36+32i)
|
|
192
|
+
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
191
193
|
# Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
|
|
192
194
|
# Complex.rect(900) * Complex.rect(1) # => (900+0i)
|
|
193
195
|
# Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
|
|
194
|
-
# Complex.rect(9, 8) *
|
|
195
|
-
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
196
|
+
# Complex.rect(9, 8) * Rational(2, 3) # => ((6/1)+(16/3)*i)
|
|
196
197
|
#
|
|
197
198
|
def *: (Numeric) -> Complex
|
|
198
199
|
|
|
199
200
|
# <!--
|
|
200
201
|
# rdoc-file=complex.c
|
|
201
|
-
# -
|
|
202
|
+
# - self ** exponent -> complex
|
|
202
203
|
# -->
|
|
203
|
-
# Returns `self` raised to power `
|
|
204
|
+
# Returns `self` raised to the power `exponent`:
|
|
204
205
|
#
|
|
205
206
|
# Complex.rect(0, 1) ** 2 # => (-1+0i)
|
|
206
207
|
# Complex.rect(-8) ** Rational(1, 3) # => (1.0000000000000002+1.7320508075688772i)
|
|
@@ -209,15 +210,25 @@ class Complex < Numeric
|
|
|
209
210
|
|
|
210
211
|
# <!--
|
|
211
212
|
# rdoc-file=complex.c
|
|
212
|
-
# -
|
|
213
|
+
# - self + other -> numeric
|
|
213
214
|
# -->
|
|
214
|
-
# Returns the sum of `self` and `
|
|
215
|
+
# Returns the sum of `self` and `other`:
|
|
216
|
+
#
|
|
217
|
+
# Complex(1, 2) + 0 # => (1+2i)
|
|
218
|
+
# Complex(1, 2) + 1 # => (2+2i)
|
|
219
|
+
# Complex(1, 2) + -1 # => (0+2i)
|
|
220
|
+
#
|
|
221
|
+
# Complex(1, 2) + 1.0 # => (2.0+2i)
|
|
222
|
+
#
|
|
223
|
+
# Complex(1, 2) + Complex(2, 1) # => (3+3i)
|
|
224
|
+
# Complex(1, 2) + Complex(2.0, 1.0) # => (3.0+3.0i)
|
|
225
|
+
#
|
|
226
|
+
# Complex(1, 2) + Rational(1, 1) # => ((2/1)+2i)
|
|
227
|
+
# Complex(1, 2) + Rational(1, 2) # => ((3/2)+2i)
|
|
228
|
+
#
|
|
229
|
+
# For a computation involving Floats, the result may be inexact (see Float#+):
|
|
215
230
|
#
|
|
216
|
-
# Complex
|
|
217
|
-
# Complex.rect(900) + Complex.rect(1) # => (901+0i)
|
|
218
|
-
# Complex.rect(-2, 9) + Complex.rect(-9, 2) # => (-11+11i)
|
|
219
|
-
# Complex.rect(9, 8) + 4 # => (13+8i)
|
|
220
|
-
# Complex.rect(20, 9) + 9.8 # => (29.8+9i)
|
|
231
|
+
# Complex(1, 2) + 3.14 # => (4.140000000000001+2i)
|
|
221
232
|
#
|
|
222
233
|
def +: (Numeric) -> Complex
|
|
223
234
|
|
|
@@ -225,9 +236,9 @@ class Complex < Numeric
|
|
|
225
236
|
|
|
226
237
|
# <!--
|
|
227
238
|
# rdoc-file=complex.c
|
|
228
|
-
# -
|
|
239
|
+
# - self - other -> complex
|
|
229
240
|
# -->
|
|
230
|
-
# Returns the difference of `self` and `
|
|
241
|
+
# Returns the difference of `self` and `other`:
|
|
231
242
|
#
|
|
232
243
|
# Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
|
|
233
244
|
# Complex.rect(900) - Complex.rect(1) # => (899+0i)
|
|
@@ -239,9 +250,9 @@ class Complex < Numeric
|
|
|
239
250
|
|
|
240
251
|
# <!--
|
|
241
252
|
# rdoc-file=complex.c
|
|
242
|
-
# - -
|
|
253
|
+
# - -self -> complex
|
|
243
254
|
# -->
|
|
244
|
-
# Returns
|
|
255
|
+
# Returns `self`, negated, which is the negation of each of its parts:
|
|
245
256
|
#
|
|
246
257
|
# -Complex.rect(1, 2) # => (-1-2i)
|
|
247
258
|
# -Complex.rect(-1, -2) # => (1+2i)
|
|
@@ -250,9 +261,9 @@ class Complex < Numeric
|
|
|
250
261
|
|
|
251
262
|
# <!--
|
|
252
263
|
# rdoc-file=complex.c
|
|
253
|
-
# -
|
|
264
|
+
# - self / other -> complex
|
|
254
265
|
# -->
|
|
255
|
-
# Returns the quotient of `self` and `
|
|
266
|
+
# Returns the quotient of `self` and `other`:
|
|
256
267
|
#
|
|
257
268
|
# Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
|
|
258
269
|
# Complex.rect(900) / Complex.rect(1) # => (900+0i)
|
|
@@ -594,9 +605,9 @@ class Complex < Numeric
|
|
|
594
605
|
|
|
595
606
|
# <!--
|
|
596
607
|
# rdoc-file=complex.c
|
|
597
|
-
# -
|
|
608
|
+
# - self / other -> complex
|
|
598
609
|
# -->
|
|
599
|
-
# Returns the quotient of `self` and `
|
|
610
|
+
# Returns the quotient of `self` and `other`:
|
|
600
611
|
#
|
|
601
612
|
# Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
|
|
602
613
|
# Complex.rect(900) / Complex.rect(1) # => (900+0i)
|
data/core/dir.rbs
CHANGED
|
@@ -477,8 +477,8 @@ class Dir
|
|
|
477
477
|
|
|
478
478
|
# <!--
|
|
479
479
|
# rdoc-file=dir.rb
|
|
480
|
-
# - Dir.glob(
|
|
481
|
-
# - Dir.glob(
|
|
480
|
+
# - Dir.glob(patterns, flags: 0, base: nil, sort: true) -> array
|
|
481
|
+
# - Dir.glob(patterns, flags: 0, base: nil, sort: true) {|entry_name| ... } -> nil
|
|
482
482
|
# -->
|
|
483
483
|
# Forms an array *entry_names* of the entry names selected by the arguments.
|
|
484
484
|
#
|
data/core/encoding.rbs
CHANGED
|
@@ -281,7 +281,7 @@ class Encoding
|
|
|
281
281
|
def inspect: () -> String
|
|
282
282
|
|
|
283
283
|
# <!-- rdoc-file=encoding.c -->
|
|
284
|
-
#
|
|
284
|
+
# The name of the encoding.
|
|
285
285
|
#
|
|
286
286
|
# Encoding::UTF_8.name #=> "UTF-8"
|
|
287
287
|
#
|
|
@@ -297,12 +297,8 @@ class Encoding
|
|
|
297
297
|
#
|
|
298
298
|
def names: () -> Array[String]
|
|
299
299
|
|
|
300
|
-
# <!--
|
|
301
|
-
#
|
|
302
|
-
# - enc.name -> string
|
|
303
|
-
# - enc.to_s -> string
|
|
304
|
-
# -->
|
|
305
|
-
# Returns the name of the encoding.
|
|
300
|
+
# <!-- rdoc-file=encoding.c -->
|
|
301
|
+
# The name of the encoding.
|
|
306
302
|
#
|
|
307
303
|
# Encoding::UTF_8.name #=> "UTF-8"
|
|
308
304
|
#
|
|
@@ -923,8 +919,9 @@ class Encoding::Converter < Object
|
|
|
923
919
|
# p ec.primitive_convert(src, dst, nil, 1) #=> :destination_buffer_full
|
|
924
920
|
# p ec.last_error #=> nil
|
|
925
921
|
#
|
|
926
|
-
def last_error: () -> Encoding::InvalidByteSequenceError
|
|
927
|
-
|
|
922
|
+
def last_error: () -> ( Encoding::InvalidByteSequenceError
|
|
923
|
+
| Encoding::UndefinedConversionError
|
|
924
|
+
| nil )
|
|
928
925
|
|
|
929
926
|
# <!--
|
|
930
927
|
# rdoc-file=transcode.c
|
data/core/enumerable.rbs
CHANGED
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
# by the block.
|
|
115
115
|
# * #grep: Returns elements selected by a given object or objects returned by
|
|
116
116
|
# a given block.
|
|
117
|
-
# * #grep_v: Returns elements selected by a given object or objects
|
|
118
|
-
# by a given block.
|
|
117
|
+
# * #grep_v: Returns elements not selected by a given object or objects
|
|
118
|
+
# returned by a given block.
|
|
119
119
|
# * #inject (aliased as #reduce): Returns the object formed by combining all
|
|
120
120
|
# elements.
|
|
121
121
|
# * #sum: Returns the sum of the elements, using method `+`.
|
|
@@ -191,6 +191,82 @@
|
|
|
191
191
|
# usage would not make sense, and so it is not shown. Example: #tally would
|
|
192
192
|
# find exactly one of each Hash entry.
|
|
193
193
|
#
|
|
194
|
+
# ## Extended Methods
|
|
195
|
+
#
|
|
196
|
+
# A Enumerable class may define extended methods. This section describes the
|
|
197
|
+
# standard behavior of extension methods for reference purposes.
|
|
198
|
+
#
|
|
199
|
+
# ### #size
|
|
200
|
+
#
|
|
201
|
+
# Enumerator has a #size method. It uses the size function argument passed to
|
|
202
|
+
# `Enumerator.new`.
|
|
203
|
+
#
|
|
204
|
+
# e = Enumerator.new(-> { 3 }) {|y| p y; y.yield :a; y.yield :b; y.yield :c; :z }
|
|
205
|
+
# p e.size #=> 3
|
|
206
|
+
# p e.next #=> :a
|
|
207
|
+
# p e.next #=> :b
|
|
208
|
+
# p e.next #=> :c
|
|
209
|
+
# begin
|
|
210
|
+
# e.next
|
|
211
|
+
# rescue StopIteration
|
|
212
|
+
# p $!.result #=> :z
|
|
213
|
+
# end
|
|
214
|
+
#
|
|
215
|
+
# The result of the size function should represent the number of iterations
|
|
216
|
+
# (i.e., the number of times Enumerator::Yielder#yield is called). In the above
|
|
217
|
+
# example, the block calls #yield three times, and the size function, +-> { 3
|
|
218
|
+
# }+, returns 3 accordingly. The result of the size function can be an integer,
|
|
219
|
+
# `Float::INFINITY`, or `nil`. An integer means the exact number of times #yield
|
|
220
|
+
# will be called, as shown above. `Float::INFINITY` indicates an infinite number
|
|
221
|
+
# of #yield calls. `nil` means the number of #yield calls is difficult or
|
|
222
|
+
# impossible to determine.
|
|
223
|
+
#
|
|
224
|
+
# Many iteration methods return an Enumerator object with an appropriate size
|
|
225
|
+
# function if no block is given.
|
|
226
|
+
#
|
|
227
|
+
# Examples:
|
|
228
|
+
#
|
|
229
|
+
# ["a", "b", "c"].each.size #=> 3
|
|
230
|
+
# {a: "x", b: "y", c: "z"}.each.size #=> 3
|
|
231
|
+
# (0..20).to_a.permutation.size #=> 51090942171709440000
|
|
232
|
+
# loop.size #=> Float::INFINITY
|
|
233
|
+
# (1..100).drop_while.size #=> nil # size depends on the block's behavior
|
|
234
|
+
# STDIN.each.size #=> nil # cannot be computed without consuming input
|
|
235
|
+
# File.open("/etc/resolv.conf").each.size #=> nil # cannot be computed without reading the file
|
|
236
|
+
#
|
|
237
|
+
# The behavior of #size for Range-based enumerators depends on the #begin
|
|
238
|
+
# element:
|
|
239
|
+
#
|
|
240
|
+
# * If the #begin element is an Integer, the #size method returns an Integer
|
|
241
|
+
# or `Float::INFINITY`.
|
|
242
|
+
# * If the #begin element is an object with a #succ method (other than
|
|
243
|
+
# Integer), #size returns `nil`. (Computing the size would require
|
|
244
|
+
# repeatedly calling #succ, which may be too slow.)
|
|
245
|
+
# * If the #begin element does not have a #succ method, #size raises a
|
|
246
|
+
# TypeError.
|
|
247
|
+
#
|
|
248
|
+
# Examples:
|
|
249
|
+
#
|
|
250
|
+
# (10..42).each.size #=> 33
|
|
251
|
+
# (10..42.9).each.size #=> 33 (the #end element may be a non-integer numeric)
|
|
252
|
+
# (10..).each.size #=> Float::INFINITY
|
|
253
|
+
# ("a".."z").each.size #=> nil
|
|
254
|
+
# ("a"..).each.size #=> nil
|
|
255
|
+
# (1.0..9.0).each.size # raises TypeError (Float does not have #succ)
|
|
256
|
+
# (..10).each.size # raises TypeError (beginless range has nil as its #begin)
|
|
257
|
+
#
|
|
258
|
+
# The Enumerable module itself does not define a #size method. A class that
|
|
259
|
+
# includes Enumerable may define its own #size method. It is recommended that
|
|
260
|
+
# such a #size method be consistent with Enumerator#size.
|
|
261
|
+
#
|
|
262
|
+
# Array and Hash implement #size and return values consistent with
|
|
263
|
+
# Enumerator#size. IO and Dir do not define #size, which is also consistent
|
|
264
|
+
# because the corresponding enumerator's size function returns `nil`.
|
|
265
|
+
#
|
|
266
|
+
# However, it is not strictly required for a class's #size method to match
|
|
267
|
+
# Enumerator#size. For example, File#size returns the number of bytes in the
|
|
268
|
+
# file, not the number of lines.
|
|
269
|
+
#
|
|
194
270
|
module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
195
271
|
# <!--
|
|
196
272
|
# rdoc-file=enum.c
|
|
@@ -438,6 +514,17 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
438
514
|
#
|
|
439
515
|
# With no block given, returns an Enumerator.
|
|
440
516
|
#
|
|
517
|
+
# e = (1..4).drop_while
|
|
518
|
+
# p e #=> #<Enumerator: 1..4:drop_while>
|
|
519
|
+
# i = e.next; p i; e.feed(i < 3) #=> 1
|
|
520
|
+
# i = e.next; p i; e.feed(i < 3) #=> 2
|
|
521
|
+
# i = e.next; p i; e.feed(i < 3) #=> 3
|
|
522
|
+
# begin
|
|
523
|
+
# e.next
|
|
524
|
+
# rescue StopIteration
|
|
525
|
+
# p $!.result #=> [3, 4]
|
|
526
|
+
# end
|
|
527
|
+
#
|
|
441
528
|
def drop_while: () { (Elem) -> boolish } -> ::Array[Elem]
|
|
442
529
|
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
|
443
530
|
|
|
@@ -2040,7 +2127,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2040
2127
|
# ["F", 6860]
|
|
2041
2128
|
#
|
|
2042
2129
|
# You can use the special symbol `:_alone` to force an element into its own
|
|
2043
|
-
# separate
|
|
2130
|
+
# separate chunk:
|
|
2044
2131
|
#
|
|
2045
2132
|
# a = [0, 0, 1, 1]
|
|
2046
2133
|
# e = a.chunk{|i| i.even? ? :_alone : true }
|