rbs 4.0.0.dev.5 → 4.0.1.dev.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 +1 -0
- data/.github/workflows/c-check.yml +8 -4
- data/.github/workflows/comments.yml +3 -1
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +10 -0
- data/.github/workflows/rust.yml +95 -0
- data/CHANGELOG.md +323 -0
- data/Rakefile +12 -29
- data/Steepfile +1 -0
- data/config.yml +393 -37
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +52 -40
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +5 -5
- data/core/enumerable.rbs +96 -91
- data/core/enumerator.rbs +4 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +36 -36
- data/core/file.rbs +186 -113
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +41 -32
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -28
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +120 -135
- data/core/kernel.rbs +189 -139
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -6
- data/core/module.rbs +146 -85
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +35 -32
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -33
- data/core/process.rbs +219 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +4 -3
- data/core/range.rbs +52 -47
- data/core/rational.rbs +5 -5
- data/core/rbs/unnamed/argf.rbs +58 -51
- data/core/rbs/unnamed/env_class.rbs +18 -13
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +7 -5
- data/core/regexp.rbs +236 -197
- data/core/ruby.rbs +1 -1
- data/core/ruby_vm.rbs +32 -30
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +1 -1
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +5 -3
- data/core/set.rbs +17 -16
- data/core/signal.rbs +2 -2
- data/core/string.rbs +311 -292
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -34
- data/core/time.rbs +47 -42
- data/core/trace_point.rbs +34 -31
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +10 -10
- data/core/warning.rbs +7 -7
- data/docs/collection.md +1 -1
- data/docs/config.md +171 -0
- data/docs/inline.md +110 -4
- data/docs/syntax.md +13 -12
- data/ext/rbs_extension/ast_translation.c +489 -135
- data/ext/rbs_extension/class_constants.c +8 -0
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/legacy_location.c +28 -51
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +12 -20
- data/include/rbs/ast.h +423 -195
- data/include/rbs/lexer.h +2 -2
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +2 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/ruby/annotations.rb +157 -4
- data/lib/rbs/ast/ruby/members.rb +374 -22
- data/lib/rbs/cli/validate.rb +5 -60
- data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
- data/lib/rbs/definition_builder.rb +60 -27
- data/lib/rbs/errors.rb +0 -11
- data/lib/rbs/inline_parser.rb +1 -1
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +1 -26
- data/lib/rbs/prototype/rbi.rb +1 -20
- data/lib/rbs/test/type_check.rb +3 -0
- data/lib/rbs/types.rb +62 -52
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +0 -1
- data/rbs.gemspec +1 -1
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/sig/ast/ruby/annotations.rbs +191 -4
- data/sig/ast/ruby/members.rbs +21 -1
- data/sig/cli/validate.rbs +1 -6
- data/sig/definition_builder.rbs +2 -0
- data/sig/errors.rbs +0 -8
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +17 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/types.rbs +10 -11
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +339 -161
- data/src/lexstate.c +1 -1
- data/src/location.c +7 -47
- data/src/parser.c +674 -480
- data/src/util/rbs_constant_pool.c +0 -4
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
- data/stdlib/cgi-escape/0/escape.rbs +4 -4
- data/stdlib/coverage/0/coverage.rbs +4 -3
- data/stdlib/date/0/date.rbs +33 -28
- data/stdlib/date/0/date_time.rbs +24 -23
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +138 -125
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +135 -108
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +159 -134
- data/stdlib/objspace/0/objspace.rbs +8 -7
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +36 -35
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +18 -14
- data/stdlib/pathname/0/pathname.rbs +2 -2
- 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 +61 -8
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +2 -2
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/securerandom.rbs +1 -1
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +10 -9
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +1 -1
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +55 -54
- data/stdlib/strscan/0/string_scanner.rbs +46 -44
- data/stdlib/tempfile/0/tempfile.rbs +24 -20
- data/stdlib/time/0/time.rbs +7 -5
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +26 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +2 -2
- 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 +6 -5
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +4 -4
- 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
- metadata +23 -5
- data/.github/workflows/valgrind.yml +0 -42
data/core/enumerable.rbs
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
# These methods return information about the Enumerable other than the elements
|
|
17
17
|
# themselves:
|
|
18
18
|
#
|
|
19
|
-
# * #member? (aliased as #include?): Returns `true` if
|
|
20
|
-
# `false` otherwise.
|
|
19
|
+
# * #member? (aliased as #include?): Returns `true` if <code>self ==
|
|
20
|
+
# object</code>, `false` otherwise.
|
|
21
21
|
# * #all?: Returns `true` if all elements meet a specified criterion; `false`
|
|
22
22
|
# otherwise.
|
|
23
23
|
# * #any?: Returns `true` if any element meets a specified criterion; `false`
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
#
|
|
36
36
|
# These methods return entries from the Enumerable, without modifying it:
|
|
37
37
|
#
|
|
38
|
-
#
|
|
38
|
+
# <em>Leading, trailing, or all elements</em>:
|
|
39
39
|
#
|
|
40
40
|
# * #to_a (aliased as #entries): Returns all elements.
|
|
41
41
|
# * #first: Returns the first element or leading elements.
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
# *Minimum and maximum value elements*:
|
|
48
48
|
#
|
|
49
49
|
# * #min: Returns the elements whose values are smallest among the elements,
|
|
50
|
-
# as determined by
|
|
50
|
+
# as determined by <code>#<=></code> or a given block.
|
|
51
51
|
# * #max: Returns the elements whose values are largest among the elements, as
|
|
52
|
-
# determined by
|
|
52
|
+
# determined by <code>#<=></code> or a given block.
|
|
53
53
|
# * #minmax: Returns a 2-element Array containing the smallest and largest
|
|
54
54
|
# elements.
|
|
55
55
|
# * #min_by: Returns the smallest element, as determined by the given block.
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
# * #minmax_by: Returns the smallest and largest elements, as determined by
|
|
58
58
|
# the given block.
|
|
59
59
|
#
|
|
60
|
-
#
|
|
60
|
+
# <em>Groups, slices, and partitions</em>:
|
|
61
61
|
#
|
|
62
62
|
# * #group_by: Returns a Hash that partitions the elements into groups.
|
|
63
63
|
# * #partition: Returns elements partitioned into two new Arrays, as
|
|
@@ -89,7 +89,8 @@
|
|
|
89
89
|
#
|
|
90
90
|
# These methods return elements in sorted order:
|
|
91
91
|
#
|
|
92
|
-
# * #sort: Returns the elements, sorted by
|
|
92
|
+
# * #sort: Returns the elements, sorted by <code>#<=></code> or the given
|
|
93
|
+
# block.
|
|
93
94
|
# * #sort_by: Returns the elements, sorted by the given block.
|
|
94
95
|
#
|
|
95
96
|
# ### Methods for Iterating
|
|
@@ -118,7 +119,7 @@
|
|
|
118
119
|
# returned by a given block.
|
|
119
120
|
# * #inject (aliased as #reduce): Returns the object formed by combining all
|
|
120
121
|
# elements.
|
|
121
|
-
# * #sum: Returns the sum of the elements, using method
|
|
122
|
+
# * #sum: Returns the sum of the elements, using method <code>+</code>.
|
|
122
123
|
# * #zip: Combines each element with elements from other enumerables; returns
|
|
123
124
|
# the n-tuples or calls the block with each.
|
|
124
125
|
# * #cycle: Calls the block with each element, cycling repeatedly.
|
|
@@ -131,8 +132,9 @@
|
|
|
131
132
|
#
|
|
132
133
|
# include Enumerable
|
|
133
134
|
#
|
|
134
|
-
# * Implement method
|
|
135
|
-
# collection. The method will be called by almost any Enumerable
|
|
135
|
+
# * Implement method <code>#each</code> which must yield successive elements
|
|
136
|
+
# of the collection. The method will be called by almost any Enumerable
|
|
137
|
+
# method.
|
|
136
138
|
#
|
|
137
139
|
# Example:
|
|
138
140
|
#
|
|
@@ -173,13 +175,15 @@
|
|
|
173
175
|
# * CSV::Row
|
|
174
176
|
# * Set
|
|
175
177
|
#
|
|
176
|
-
# Virtually all methods in Enumerable call method
|
|
177
|
-
# class:
|
|
178
|
+
# Virtually all methods in Enumerable call method <code>#each</code> in the
|
|
179
|
+
# including class:
|
|
178
180
|
#
|
|
179
|
-
# *
|
|
180
|
-
#
|
|
181
|
-
# *
|
|
182
|
-
#
|
|
181
|
+
# * <code>Hash#each</code> yields the next key-value pair as a 2-element
|
|
182
|
+
# Array.
|
|
183
|
+
# * <code>Struct#each</code> yields the next name-value pair as a 2-element
|
|
184
|
+
# Array.
|
|
185
|
+
# * For the other classes above, <code>#each</code> yields the next object
|
|
186
|
+
# from the collection.
|
|
183
187
|
#
|
|
184
188
|
# ## About the Examples
|
|
185
189
|
#
|
|
@@ -199,7 +203,7 @@
|
|
|
199
203
|
# ### #size
|
|
200
204
|
#
|
|
201
205
|
# Enumerator has a #size method. It uses the size function argument passed to
|
|
202
|
-
#
|
|
206
|
+
# <code>Enumerator.new</code>.
|
|
203
207
|
#
|
|
204
208
|
# e = Enumerator.new(-> { 3 }) {|y| p y; y.yield :a; y.yield :b; y.yield :c; :z }
|
|
205
209
|
# p e.size #=> 3
|
|
@@ -216,10 +220,10 @@
|
|
|
216
220
|
# (i.e., the number of times Enumerator::Yielder#yield is called). In the above
|
|
217
221
|
# example, the block calls #yield three times, and the size function, +-> { 3
|
|
218
222
|
# }+, returns 3 accordingly. The result of the size function can be an integer,
|
|
219
|
-
#
|
|
220
|
-
# will be called, as shown above.
|
|
221
|
-
# of #yield calls. `nil` means the number of #yield
|
|
222
|
-
# impossible to determine.
|
|
223
|
+
# <code>Float::INFINITY</code>, or `nil`. An integer means the exact number of
|
|
224
|
+
# times #yield will be called, as shown above. <code>Float::INFINITY</code>
|
|
225
|
+
# indicates an infinite number of #yield calls. `nil` means the number of #yield
|
|
226
|
+
# calls is difficult or impossible to determine.
|
|
223
227
|
#
|
|
224
228
|
# Many iteration methods return an Enumerator object with an appropriate size
|
|
225
229
|
# function if no block is given.
|
|
@@ -238,7 +242,7 @@
|
|
|
238
242
|
# element:
|
|
239
243
|
#
|
|
240
244
|
# * If the #begin element is an Integer, the #size method returns an Integer
|
|
241
|
-
# or
|
|
245
|
+
# or <code>Float::INFINITY</code>.
|
|
242
246
|
# * If the #begin element is an object with a #succ method (other than
|
|
243
247
|
# Integer), #size returns `nil`. (Computing the size would require
|
|
244
248
|
# repeatedly calling #succ, which may be too slow.)
|
|
@@ -292,7 +296,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
292
296
|
# [].all? # => true
|
|
293
297
|
#
|
|
294
298
|
# With argument `pattern` and no block, returns whether for each element
|
|
295
|
-
# `element`,
|
|
299
|
+
# `element`, <code>pattern === element</code>:
|
|
296
300
|
#
|
|
297
301
|
# (1..4).all?(Integer) # => true
|
|
298
302
|
# (1..4).all?(Numeric) # => true
|
|
@@ -336,7 +340,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
336
340
|
# [].any? # => false
|
|
337
341
|
#
|
|
338
342
|
# With argument `pattern` and no block, returns whether for any element
|
|
339
|
-
# `element`,
|
|
343
|
+
# `element`, <code>pattern === element</code>:
|
|
340
344
|
#
|
|
341
345
|
# [nil, false, 0].any?(Integer) # => true
|
|
342
346
|
# [nil, false, 0].any?(Numeric) # => true
|
|
@@ -423,8 +427,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
423
427
|
# [0, 1, 2].count # => 3
|
|
424
428
|
# {foo: 0, bar: 1, baz: 2}.count # => 3
|
|
425
429
|
#
|
|
426
|
-
# With argument `object` given, returns the number of elements that are
|
|
427
|
-
# `object`:
|
|
430
|
+
# With argument `object` given, returns the number of elements that are
|
|
431
|
+
# <code>==</code> to `object`:
|
|
428
432
|
#
|
|
429
433
|
# [0, 1, 2, 1].count(1) # => 2
|
|
430
434
|
#
|
|
@@ -562,8 +566,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
562
566
|
# - each_with_index(*args) {|element, i| ..... } -> self
|
|
563
567
|
# - each_with_index(*args) -> enumerator
|
|
564
568
|
# -->
|
|
565
|
-
# Invoke
|
|
566
|
-
# element and its index; returns `self`:
|
|
569
|
+
# Invoke <code>self.each</code> with <code>*args</code>. With a block given, the
|
|
570
|
+
# block receives each element and its index; returns `self`:
|
|
567
571
|
#
|
|
568
572
|
# h = {}
|
|
569
573
|
# (1..4).each_with_index {|element, i| h[element] = i } # => 1..4
|
|
@@ -680,7 +684,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
680
684
|
# `nil` if no such element is found.
|
|
681
685
|
#
|
|
682
686
|
# With argument `object` given, returns the index of the first element that is
|
|
683
|
-
#
|
|
687
|
+
# <code>==</code> `object`:
|
|
684
688
|
#
|
|
685
689
|
# ['a', 'b', 'c', 'b'].find_index('b') # => 1
|
|
686
690
|
#
|
|
@@ -731,7 +735,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
731
735
|
# pattern.
|
|
732
736
|
#
|
|
733
737
|
# With no block given, returns an array containing each element for which
|
|
734
|
-
#
|
|
738
|
+
# <code>pattern === element</code> is `true`:
|
|
735
739
|
#
|
|
736
740
|
# a = ['foo', 'bar', 'car', 'moo']
|
|
737
741
|
# a.grep(/ar/) # => ["bar", "car"]
|
|
@@ -754,11 +758,11 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
754
758
|
# - grep_v(pattern) -> array
|
|
755
759
|
# - grep_v(pattern) {|element| ... } -> array
|
|
756
760
|
# -->
|
|
757
|
-
# Returns an array of objects based on elements of `self` that
|
|
758
|
-
# given pattern.
|
|
761
|
+
# Returns an array of objects based on elements of `self` that <em>don't</em>
|
|
762
|
+
# match the given pattern.
|
|
759
763
|
#
|
|
760
764
|
# With no block given, returns an array containing each element for which
|
|
761
|
-
#
|
|
765
|
+
# <code>pattern === element</code> is `false`:
|
|
762
766
|
#
|
|
763
767
|
# a = ['foo', 'bar', 'car', 'moo']
|
|
764
768
|
# a.grep_v(/ar/) # => ["foo", "moo"]
|
|
@@ -801,7 +805,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
801
805
|
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
|
802
806
|
|
|
803
807
|
# <!-- rdoc-file=enum.c -->
|
|
804
|
-
# Returns whether for any element
|
|
808
|
+
# Returns whether for any element <code>object == element</code>:
|
|
805
809
|
#
|
|
806
810
|
# (1..4).include?(2) # => true
|
|
807
811
|
# (1..4).include?(5) # => false
|
|
@@ -812,7 +816,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
812
816
|
# {foo: 0, bar: 1, baz: 2}.include?('foo') # => false
|
|
813
817
|
# {foo: 0, bar: 1, baz: 2}.include?(0) # => false
|
|
814
818
|
#
|
|
815
|
-
def include?: (
|
|
819
|
+
def include?: (top arg0) -> bool
|
|
816
820
|
|
|
817
821
|
# <!--
|
|
818
822
|
# rdoc-file=enum.c
|
|
@@ -859,13 +863,13 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
859
863
|
# product #=> 24
|
|
860
864
|
#
|
|
861
865
|
# When this runs, the block is first called with `1` (the initial value) and `2`
|
|
862
|
-
# (the first element of the array). The block returns
|
|
863
|
-
# iteration the block is called with `2` (the previous result) and `3`.
|
|
864
|
-
# block returns `6`, and is called one last time with `6` and `4`. The
|
|
865
|
-
# the block, `24` becomes the value returned by `inject`. This code
|
|
866
|
-
# product of the elements in the enumerable.
|
|
866
|
+
# (the first element of the array). The block returns <code>1*2</code>, so on
|
|
867
|
+
# the next iteration the block is called with `2` (the previous result) and `3`.
|
|
868
|
+
# The block returns `6`, and is called one last time with `6` and `4`. The
|
|
869
|
+
# result of the block, `24` becomes the value returned by `inject`. This code
|
|
870
|
+
# returns the product of the elements in the enumerable.
|
|
867
871
|
#
|
|
868
|
-
#
|
|
872
|
+
# <strong>First Shortcut: Default Initial value</strong>
|
|
869
873
|
#
|
|
870
874
|
# In the case of the previous example, the initial value, `1`, wasn't really
|
|
871
875
|
# necessary: the calculation of the product of a list of numbers is
|
|
@@ -902,7 +906,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
902
906
|
# Note that the last line of the block is just the word `counts`. This ensures
|
|
903
907
|
# the return value of the block is the result that's being calculated.
|
|
904
908
|
#
|
|
905
|
-
#
|
|
909
|
+
# <strong>Second Shortcut: a Reducer function</strong>
|
|
906
910
|
#
|
|
907
911
|
# A *reducer function* is a function that takes a partial result and the next
|
|
908
912
|
# value, returning the next partial result. The block that is given to `inject`
|
|
@@ -947,11 +951,11 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
947
951
|
# position = "nnneesw".chars.reduce(Turtle.new, :move)
|
|
948
952
|
# position #=>> #<Turtle:0x00000001052f4698 @y=2, @x=1>
|
|
949
953
|
#
|
|
950
|
-
#
|
|
954
|
+
# <strong>Third Shortcut: Reducer With no Initial Value</strong>
|
|
951
955
|
#
|
|
952
956
|
# If your reducer returns a value that it can accept as a parameter, then you
|
|
953
|
-
# don't have to pass in an initial value. Here
|
|
954
|
-
# function:
|
|
957
|
+
# don't have to pass in an initial value. Here <code>:*</code> is the name of
|
|
958
|
+
# the *times* function:
|
|
955
959
|
#
|
|
956
960
|
# product = [ 2, 3, 4 ].inject(:*)
|
|
957
961
|
# product # => 24
|
|
@@ -982,7 +986,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
982
986
|
# The ordering of equal elements is indeterminate and may be unstable.
|
|
983
987
|
#
|
|
984
988
|
# With no argument and no block, returns the maximum element, using the
|
|
985
|
-
# elements' own method
|
|
989
|
+
# elements' own method <code>#<=></code> for comparison:
|
|
986
990
|
#
|
|
987
991
|
# (1..4).max # => 4
|
|
988
992
|
# (-4..-1).max # => -1
|
|
@@ -1002,9 +1006,9 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1002
1006
|
# With a block given, the block determines the maximum elements. The block is
|
|
1003
1007
|
# called with two elements `a` and `b`, and must return:
|
|
1004
1008
|
#
|
|
1005
|
-
# * A negative integer if
|
|
1006
|
-
# * Zero if
|
|
1007
|
-
# * A positive integer if
|
|
1009
|
+
# * A negative integer if <code>a < b</code>.
|
|
1010
|
+
# * Zero if <code>a == b</code>.
|
|
1011
|
+
# * A positive integer if <code>a > b</code>.
|
|
1008
1012
|
#
|
|
1009
1013
|
# With a block given and no argument, returns the maximum element as determined
|
|
1010
1014
|
# by the block:
|
|
@@ -1080,7 +1084,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1080
1084
|
# The ordering of equal elements is indeterminate and may be unstable.
|
|
1081
1085
|
#
|
|
1082
1086
|
# With no argument and no block, returns the minimum element, using the
|
|
1083
|
-
# elements' own method
|
|
1087
|
+
# elements' own method <code>#<=></code> for comparison:
|
|
1084
1088
|
#
|
|
1085
1089
|
# (1..4).min # => 1
|
|
1086
1090
|
# (-4..-1).min # => -4
|
|
@@ -1100,9 +1104,9 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1100
1104
|
# With a block given, the block determines the minimum elements. The block is
|
|
1101
1105
|
# called with two elements `a` and `b`, and must return:
|
|
1102
1106
|
#
|
|
1103
|
-
# * A negative integer if
|
|
1104
|
-
# * Zero if
|
|
1105
|
-
# * A positive integer if
|
|
1107
|
+
# * A negative integer if <code>a < b</code>.
|
|
1108
|
+
# * Zero if <code>a == b</code>.
|
|
1109
|
+
# * A positive integer if <code>a > b</code>.
|
|
1106
1110
|
#
|
|
1107
1111
|
# With a block given and no argument, returns the minimum element as determined
|
|
1108
1112
|
# by the block:
|
|
@@ -1177,7 +1181,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1177
1181
|
# indeterminate and may be unstable.
|
|
1178
1182
|
#
|
|
1179
1183
|
# With no argument and no block, returns the minimum and maximum elements, using
|
|
1180
|
-
# the elements' own method
|
|
1184
|
+
# the elements' own method <code>#<=></code> for comparison:
|
|
1181
1185
|
#
|
|
1182
1186
|
# (1..4).minmax # => [1, 4]
|
|
1183
1187
|
# (-4..-1).minmax # => [-4, -1]
|
|
@@ -1240,7 +1244,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1240
1244
|
# [].none? # => true
|
|
1241
1245
|
#
|
|
1242
1246
|
# With argument `pattern` and no block, returns whether for no element
|
|
1243
|
-
# `element`,
|
|
1247
|
+
# `element`, <code>pattern === element</code>:
|
|
1244
1248
|
#
|
|
1245
1249
|
# [nil, false, 1.1].none?(Integer) # => true
|
|
1246
1250
|
# %w[bar baz bat bam].none?(/m/) # => false
|
|
@@ -1282,7 +1286,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1282
1286
|
# [].one? # => false
|
|
1283
1287
|
#
|
|
1284
1288
|
# With argument `pattern` and no block, returns whether for exactly one element
|
|
1285
|
-
# `element`,
|
|
1289
|
+
# `element`, <code>pattern === element</code>:
|
|
1286
1290
|
#
|
|
1287
1291
|
# [nil, false, 0].one?(Integer) # => true
|
|
1288
1292
|
# [nil, false, 0].one?(Numeric) # => true
|
|
@@ -1393,7 +1397,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1393
1397
|
# Returns an array containing the sorted elements of `self`. The ordering of
|
|
1394
1398
|
# equal elements is indeterminate and may be unstable.
|
|
1395
1399
|
#
|
|
1396
|
-
# With no block given, the sort compares using the elements' own method
|
|
1400
|
+
# With no block given, the sort compares using the elements' own method
|
|
1401
|
+
# <code>#<=></code>:
|
|
1397
1402
|
#
|
|
1398
1403
|
# %w[b c a d].sort # => ["a", "b", "c", "d"]
|
|
1399
1404
|
# {foo: 0, bar: 1, baz: 2}.sort # => [[:bar, 1], [:baz, 2], [:foo, 0]]
|
|
@@ -1401,9 +1406,9 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1401
1406
|
# With a block given, comparisons in the block determine the ordering. The block
|
|
1402
1407
|
# is called with two elements `a` and `b`, and must return:
|
|
1403
1408
|
#
|
|
1404
|
-
# * A negative integer if
|
|
1405
|
-
# * Zero if
|
|
1406
|
-
# * A positive integer if
|
|
1409
|
+
# * A negative integer if <code>a < b</code>.
|
|
1410
|
+
# * Zero if <code>a == b</code>.
|
|
1411
|
+
# * A positive integer if <code>a > b</code>.
|
|
1407
1412
|
#
|
|
1408
1413
|
# Examples:
|
|
1409
1414
|
#
|
|
@@ -1451,7 +1456,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1451
1456
|
# b.report("Sort by") { a.sort_by { |a| a } }
|
|
1452
1457
|
# end
|
|
1453
1458
|
#
|
|
1454
|
-
#
|
|
1459
|
+
# <em>produces:</em>
|
|
1455
1460
|
#
|
|
1456
1461
|
# user system total real
|
|
1457
1462
|
# Sort 0.180000 0.000000 0.180000 ( 0.175469)
|
|
@@ -1647,7 +1652,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1647
1652
|
# rdoc-file=enum.c
|
|
1648
1653
|
# - include?(object) -> true or false
|
|
1649
1654
|
# -->
|
|
1650
|
-
# Returns whether for any element
|
|
1655
|
+
# Returns whether for any element <code>object == element</code>:
|
|
1651
1656
|
#
|
|
1652
1657
|
# (1..4).include?(2) # => true
|
|
1653
1658
|
# (1..4).include?(5) # => false
|
|
@@ -1658,7 +1663,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1658
1663
|
# {foo: 0, bar: 1, baz: 2}.include?('foo') # => false
|
|
1659
1664
|
# {foo: 0, bar: 1, baz: 2}.include?(0) # => false
|
|
1660
1665
|
#
|
|
1661
|
-
def member?: (
|
|
1666
|
+
def member?: (top arg0) -> bool
|
|
1662
1667
|
|
|
1663
1668
|
# <!-- rdoc-file=enum.c -->
|
|
1664
1669
|
# Returns the result of applying a reducer to an initial value and the first
|
|
@@ -1699,13 +1704,13 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1699
1704
|
# product #=> 24
|
|
1700
1705
|
#
|
|
1701
1706
|
# When this runs, the block is first called with `1` (the initial value) and `2`
|
|
1702
|
-
# (the first element of the array). The block returns
|
|
1703
|
-
# iteration the block is called with `2` (the previous result) and `3`.
|
|
1704
|
-
# block returns `6`, and is called one last time with `6` and `4`. The
|
|
1705
|
-
# the block, `24` becomes the value returned by `inject`. This code
|
|
1706
|
-
# product of the elements in the enumerable.
|
|
1707
|
+
# (the first element of the array). The block returns <code>1*2</code>, so on
|
|
1708
|
+
# the next iteration the block is called with `2` (the previous result) and `3`.
|
|
1709
|
+
# The block returns `6`, and is called one last time with `6` and `4`. The
|
|
1710
|
+
# result of the block, `24` becomes the value returned by `inject`. This code
|
|
1711
|
+
# returns the product of the elements in the enumerable.
|
|
1707
1712
|
#
|
|
1708
|
-
#
|
|
1713
|
+
# <strong>First Shortcut: Default Initial value</strong>
|
|
1709
1714
|
#
|
|
1710
1715
|
# In the case of the previous example, the initial value, `1`, wasn't really
|
|
1711
1716
|
# necessary: the calculation of the product of a list of numbers is
|
|
@@ -1742,7 +1747,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1742
1747
|
# Note that the last line of the block is just the word `counts`. This ensures
|
|
1743
1748
|
# the return value of the block is the result that's being calculated.
|
|
1744
1749
|
#
|
|
1745
|
-
#
|
|
1750
|
+
# <strong>Second Shortcut: a Reducer function</strong>
|
|
1746
1751
|
#
|
|
1747
1752
|
# A *reducer function* is a function that takes a partial result and the next
|
|
1748
1753
|
# value, returning the next partial result. The block that is given to `inject`
|
|
@@ -1787,11 +1792,11 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1787
1792
|
# position = "nnneesw".chars.reduce(Turtle.new, :move)
|
|
1788
1793
|
# position #=>> #<Turtle:0x00000001052f4698 @y=2, @x=1>
|
|
1789
1794
|
#
|
|
1790
|
-
#
|
|
1795
|
+
# <strong>Third Shortcut: Reducer With no Initial Value</strong>
|
|
1791
1796
|
#
|
|
1792
1797
|
# If your reducer returns a value that it can accept as a parameter, then you
|
|
1793
|
-
# don't have to pass in an initial value. Here
|
|
1794
|
-
# function:
|
|
1798
|
+
# don't have to pass in an initial value. Here <code>:*</code> is the name of
|
|
1799
|
+
# the *times* function:
|
|
1795
1800
|
#
|
|
1796
1801
|
# product = [ 2, 3, 4 ].inject(:*)
|
|
1797
1802
|
# product # => 24
|
|
@@ -1854,7 +1859,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1854
1859
|
# - uniq {|element| ... } -> array
|
|
1855
1860
|
# -->
|
|
1856
1861
|
# With no block, returns a new array containing only unique elements; the array
|
|
1857
|
-
# has no two elements `e0` and `e1` such that
|
|
1862
|
+
# has no two elements `e0` and `e1` such that <code>e0.eql?(e1)</code>:
|
|
1858
1863
|
#
|
|
1859
1864
|
# %w[a b c c b a a b c].uniq # => ["a", "b", "c"]
|
|
1860
1865
|
# [0, 1, 2, 2, 1, 0, 0, 1, 2].uniq # => [0, 1, 2]
|
|
@@ -1881,12 +1886,12 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
1881
1886
|
# (1..100).sum(1) # => 5051
|
|
1882
1887
|
# ('a'..'d').sum('foo') # => "fooabcd"
|
|
1883
1888
|
#
|
|
1884
|
-
# Generally, the sum is computed using methods
|
|
1885
|
-
# optimizations, those methods may not be used, and so any
|
|
1886
|
-
# methods may not have effect here.
|
|
1889
|
+
# Generally, the sum is computed using methods <code>+</code> and `each`; for
|
|
1890
|
+
# performance optimizations, those methods may not be used, and so any
|
|
1891
|
+
# redefinition of those methods may not have effect here.
|
|
1887
1892
|
#
|
|
1888
1893
|
# One such optimization: When possible, computes using Gauss's summation formula
|
|
1889
|
-
#
|
|
1894
|
+
# <em>n(n+1)/2</em>:
|
|
1890
1895
|
#
|
|
1891
1896
|
# 100 * (100 + 1) / 2 # => 5050
|
|
1892
1897
|
#
|
|
@@ -2025,8 +2030,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2025
2030
|
# - zip(*other_enums) {|array| ... } -> nil
|
|
2026
2031
|
# -->
|
|
2027
2032
|
# With no block given, returns a new array `new_array` of size self.size whose
|
|
2028
|
-
# elements are arrays. Each nested array
|
|
2029
|
-
#
|
|
2033
|
+
# elements are arrays. Each nested array <code>new_array[n]</code> is of size
|
|
2034
|
+
# <code>other_enums.size+1</code>, and contains:
|
|
2030
2035
|
#
|
|
2031
2036
|
# * The `n`-th element of self.
|
|
2032
2037
|
# * The `n`-th element of each of the `other_enums`.
|
|
@@ -2050,8 +2055,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2050
2055
|
# # [[:baz, 2], [:gaz, 5], [:haz, 8]]
|
|
2051
2056
|
# # ]
|
|
2052
2057
|
#
|
|
2053
|
-
# If any enumerable in other_enums is smaller than self, fills to
|
|
2054
|
-
# with `nil`:
|
|
2058
|
+
# If any enumerable in other_enums is smaller than self, fills to
|
|
2059
|
+
# <code>self.size</code> with `nil`:
|
|
2055
2060
|
#
|
|
2056
2061
|
# a = [:a0, :a1, :a2, :a3]
|
|
2057
2062
|
# b = [:b0, :b1, :b2]
|
|
@@ -2135,8 +2140,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2135
2140
|
# ["E", 8736]
|
|
2136
2141
|
# ["F", 6860]
|
|
2137
2142
|
#
|
|
2138
|
-
# You can use the special symbol
|
|
2139
|
-
# separate chunk:
|
|
2143
|
+
# You can use the special symbol <code>:_alone</code> to force an element into
|
|
2144
|
+
# its own separate chunk:
|
|
2140
2145
|
#
|
|
2141
2146
|
# a = [0, 0, 1, 1]
|
|
2142
2147
|
# e = a.chunk{|i| i.even? ? :_alone : true }
|
|
@@ -2151,8 +2156,8 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2151
2156
|
# }
|
|
2152
2157
|
# }
|
|
2153
2158
|
#
|
|
2154
|
-
# You can use the special symbol
|
|
2155
|
-
# be ignored (not included in any chunk):
|
|
2159
|
+
# You can use the special symbol <code>:_separator</code> or `nil` to force an
|
|
2160
|
+
# element to be ignored (not included in any chunk):
|
|
2156
2161
|
#
|
|
2157
2162
|
# a = [0, 0, -1, 1, 1]
|
|
2158
2163
|
# e = a.chunk{|i| i < 0 ? :_separator : true }
|
|
@@ -2314,11 +2319,11 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2314
2319
|
# Creates an enumerator for each chunked elements. The ends of chunks are
|
|
2315
2320
|
# defined by *pattern* and the block.
|
|
2316
2321
|
#
|
|
2317
|
-
# If
|
|
2318
|
-
# element, the element is end of a chunk.
|
|
2322
|
+
# If <code>_pattern_ === _elt_</code> returns `true` or the block returns `true`
|
|
2323
|
+
# for the element, the element is end of a chunk.
|
|
2319
2324
|
#
|
|
2320
|
-
# The
|
|
2321
|
-
# *enum*.
|
|
2325
|
+
# The <code>===</code> and *block* is called from the first element to the last
|
|
2326
|
+
# element of *enum*.
|
|
2322
2327
|
#
|
|
2323
2328
|
# The result enumerator yields the chunked elements as an array. So `each`
|
|
2324
2329
|
# method can be called as follows:
|
|
@@ -2349,7 +2354,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2349
2354
|
# -->
|
|
2350
2355
|
# With argument `pattern`, returns an enumerator that uses the pattern to
|
|
2351
2356
|
# partition elements into arrays ("slices"). An element begins a new slice if
|
|
2352
|
-
#
|
|
2357
|
+
# <code>element === pattern</code> (or if it is the first element).
|
|
2353
2358
|
#
|
|
2354
2359
|
# a = %w[foo bar fop for baz fob fog bam foy]
|
|
2355
2360
|
# e = a.slice_before(/ba/) # => #<Enumerator: ...>
|
data/core/enumerator.rbs
CHANGED
|
@@ -171,8 +171,9 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
|
|
|
171
171
|
#
|
|
172
172
|
# The optional `size` keyword argument specifies the size of the enumerator,
|
|
173
173
|
# which can be retrieved by Enumerator#size. It can be an integer,
|
|
174
|
-
#
|
|
175
|
-
# unknown size. When not specified, the size defaults to
|
|
174
|
+
# <code>Float::INFINITY</code>, a callable object (such as a lambda), or `nil`
|
|
175
|
+
# to indicate unknown size. When not specified, the size defaults to
|
|
176
|
+
# <code>Float::INFINITY</code>.
|
|
176
177
|
#
|
|
177
178
|
# # Infinite enumerator
|
|
178
179
|
# enum = Enumerator.produce(1, size: Float::INFINITY, &:succ)
|
|
@@ -305,7 +306,7 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
|
|
|
305
306
|
#
|
|
306
307
|
# Iteration is defined by the given block, in which a "yielder" object, given as
|
|
307
308
|
# block parameter, can be used to yield a value by calling the `yield` method
|
|
308
|
-
# (aliased as
|
|
309
|
+
# (aliased as <code><<</code>):
|
|
309
310
|
#
|
|
310
311
|
# fib = Enumerator.new do |y|
|
|
311
312
|
# a = b = 1
|
data/core/errno.rbs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#
|
|
10
10
|
# When the Ruby interpreter interacts with the operating system and receives
|
|
11
11
|
# such an error code (e.g., `2`), it maps the code to a particular Ruby
|
|
12
|
-
# exception class (e.g.,
|
|
12
|
+
# exception class (e.g., <code>Errno::ENOENT</code>):
|
|
13
13
|
#
|
|
14
14
|
# File.open('nosuch.txt')
|
|
15
15
|
# # => No such file or directory @ rb_sysopen - nosuch.txt (Errno::ENOENT)
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
# Errno::ENOENT.superclass # => SystemCallError
|
|
26
26
|
# Errno::ENOENT::Errno # => 2
|
|
27
27
|
#
|
|
28
|
-
# The names of nested classes are returned by method
|
|
28
|
+
# The names of nested classes are returned by method
|
|
29
|
+
# <code>Errno.constants</code>:
|
|
29
30
|
#
|
|
30
31
|
# Errno.constants.size # => 158
|
|
31
32
|
# Errno.constants.sort.take(5) # => [:E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, :EADV]
|