rbs 4.0.0.dev.4 → 4.0.0.dev.5
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/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +11 -8
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +17 -34
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/valgrind.yml +42 -0
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/README.md +1 -1
- data/Rakefile +32 -5
- data/config.yml +46 -0
- data/core/array.rbs +96 -46
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/comparable.rbs +13 -6
- data/core/complex.rbs +55 -41
- data/core/dir.rbs +4 -4
- data/core/encoding.rbs +7 -10
- data/core/enumerable.rbs +90 -3
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +63 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +40 -20
- data/core/file.rbs +108 -78
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +225 -69
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1023 -727
- data/core/integer.rbs +104 -110
- data/core/io/buffer.rbs +21 -10
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +82 -19
- data/core/kernel.rbs +70 -59
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +63 -27
- data/core/module.rbs +103 -26
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +43 -35
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/core/pathname.rbs +1272 -0
- data/core/proc.rbs +30 -25
- data/core/process.rbs +4 -2
- data/core/ractor.rbs +361 -509
- data/core/random.rbs +17 -0
- data/core/range.rbs +113 -16
- data/core/rational.rbs +56 -85
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -113
- 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/signal.rbs +24 -14
- data/core/string.rbs +3171 -1241
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +17 -11
- data/core/thread.rbs +95 -33
- 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/inline.md +470 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +33 -4
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +77 -3
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +8 -2
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +5 -5
- data/ext/rbs_extension/main.c +37 -20
- data/include/rbs/ast.h +85 -38
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -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 +137 -0
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +159 -1
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -51
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +91 -2
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -7
- data/lib/rbs/inline_parser.rb +341 -5
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +2 -2
- data/lib/rbs/prototype/rbi.rb +2 -0
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +16 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +27 -27
- data/lib/rbs/validator.rb +2 -2
- 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 +1 -1
- data/rbs.gemspec +3 -2
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +124 -0
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +87 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +13 -4
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +16 -2
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +4 -4
- data/src/ast.c +80 -1
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +4 -4
- data/src/parser.c +412 -145
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -10
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- 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 +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 +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/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +20 -14
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +82 -28
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -27
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/open3/0/open3.rbs +459 -1
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +8 -3
- data/stdlib/pathname/0/pathname.rbs +9 -1379
- data/stdlib/psych/0/psych.rbs +4 -4
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +2 -2
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +6 -19
- 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 +16 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +24 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/gzip_writer.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +30 -4
data/core/dir.rbs
CHANGED
|
@@ -171,7 +171,7 @@ class Dir
|
|
|
171
171
|
# system's encoding is used:
|
|
172
172
|
#
|
|
173
173
|
# Dir.new('.').read.encoding # => #<Encoding:UTF-8>
|
|
174
|
-
# Dir.new('.', encoding:
|
|
174
|
+
# Dir.new('.', encoding: Encoding::US_ASCI).read.encoding # => #<Encoding:US-ASCII>
|
|
175
175
|
#
|
|
176
176
|
def initialize: (path dir, ?encoding: encoding?) -> void
|
|
177
177
|
|
|
@@ -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
|
#
|
|
@@ -704,7 +704,7 @@ class Dir
|
|
|
704
704
|
# system's encoding is used:
|
|
705
705
|
#
|
|
706
706
|
# Dir.open('.').read.encoding # => #<Encoding:UTF-8>
|
|
707
|
-
# Dir.open('.', encoding:
|
|
707
|
+
# Dir.open('.', encoding: Encoding::US_ASCII).read.encoding # => #<Encoding:US-ASCII>
|
|
708
708
|
#
|
|
709
709
|
def self.open: (path dirname, ?encoding: encoding?) -> instance
|
|
710
710
|
| [U] (path dirname, ?encoding: encoding?) { (instance) -> U } -> U
|
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
|
#
|
|
@@ -785,7 +781,7 @@ class Encoding::Converter < Object
|
|
|
785
781
|
# - ec == other -> true or false
|
|
786
782
|
# -->
|
|
787
783
|
#
|
|
788
|
-
def ==: (
|
|
784
|
+
def ==: (untyped) -> bool
|
|
789
785
|
|
|
790
786
|
# <!--
|
|
791
787
|
# rdoc-file=transcode.c
|
|
@@ -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
|
%a{private}
|
|
196
272
|
interface _Pattern
|
|
@@ -445,6 +521,17 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
445
521
|
#
|
|
446
522
|
# With no block given, returns an Enumerator.
|
|
447
523
|
#
|
|
524
|
+
# e = (1..4).drop_while
|
|
525
|
+
# p e #=> #<Enumerator: 1..4:drop_while>
|
|
526
|
+
# i = e.next; p i; e.feed(i < 3) #=> 1
|
|
527
|
+
# i = e.next; p i; e.feed(i < 3) #=> 2
|
|
528
|
+
# i = e.next; p i; e.feed(i < 3) #=> 3
|
|
529
|
+
# begin
|
|
530
|
+
# e.next
|
|
531
|
+
# rescue StopIteration
|
|
532
|
+
# p $!.result #=> [3, 4]
|
|
533
|
+
# end
|
|
534
|
+
#
|
|
448
535
|
def drop_while: () { (Elem) -> boolish } -> ::Array[Elem]
|
|
449
536
|
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
|
450
537
|
|
|
@@ -2049,7 +2136,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
|
|
|
2049
2136
|
# ["F", 6860]
|
|
2050
2137
|
#
|
|
2051
2138
|
# You can use the special symbol `:_alone` to force an element into its own
|
|
2052
|
-
# separate
|
|
2139
|
+
# separate chunk:
|
|
2053
2140
|
#
|
|
2054
2141
|
# a = [0, 0, 1, 1]
|
|
2055
2142
|
# e = a.chunk{|i| i.even? ? :_alone : true }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# <!-- rdoc-file=enumerator.c -->
|
|
2
|
+
# Enumerator::ArithmeticSequence is a subclass of Enumerator, that is a
|
|
3
|
+
# representation of sequences of numbers with common difference. Instances of
|
|
4
|
+
# this class can be generated by the Range#step and Numeric#step methods.
|
|
5
|
+
#
|
|
6
|
+
# The class can be used for slicing Array (see Array#slice) or custom
|
|
7
|
+
# collections.
|
|
8
|
+
#
|
|
9
|
+
class Enumerator::ArithmeticSequence < Enumerator[Numeric]
|
|
10
|
+
# <!--
|
|
11
|
+
# rdoc-file=enumerator.c
|
|
12
|
+
# - aseq.begin -> num or nil
|
|
13
|
+
# -->
|
|
14
|
+
# Returns the number that defines the first element of this arithmetic sequence.
|
|
15
|
+
#
|
|
16
|
+
def begin: () -> Numeric?
|
|
17
|
+
|
|
18
|
+
# <!--
|
|
19
|
+
# rdoc-file=enumerator.c
|
|
20
|
+
# - aseq.end -> num or nil
|
|
21
|
+
# -->
|
|
22
|
+
# Returns the number that defines the end of this arithmetic sequence.
|
|
23
|
+
#
|
|
24
|
+
def end: () -> Numeric?
|
|
25
|
+
|
|
26
|
+
# <!--
|
|
27
|
+
# rdoc-file=enumerator.c
|
|
28
|
+
# - aseq.each {|i| block } -> aseq
|
|
29
|
+
# - aseq.each -> aseq
|
|
30
|
+
# -->
|
|
31
|
+
#
|
|
32
|
+
def each: () ?{ (Numeric) -> void } -> self
|
|
33
|
+
|
|
34
|
+
# <!--
|
|
35
|
+
# rdoc-file=enumerator.c
|
|
36
|
+
# - aseq.exclude_end? -> true or false
|
|
37
|
+
# -->
|
|
38
|
+
# Returns `true` if this arithmetic sequence excludes its end value.
|
|
39
|
+
#
|
|
40
|
+
def exclude_end?: () -> bool
|
|
41
|
+
|
|
42
|
+
# <!--
|
|
43
|
+
# rdoc-file=enumerator.c
|
|
44
|
+
# - aseq.last -> num or nil
|
|
45
|
+
# - aseq.last(n) -> an_array
|
|
46
|
+
# -->
|
|
47
|
+
# Returns the last number in this arithmetic sequence, or an array of the last
|
|
48
|
+
# `n` elements.
|
|
49
|
+
#
|
|
50
|
+
def last: () -> Numeric?
|
|
51
|
+
| (Integer n) -> Array[Numeric]
|
|
52
|
+
|
|
53
|
+
# <!--
|
|
54
|
+
# rdoc-file=enumerator.c
|
|
55
|
+
# - aseq.size -> num or nil
|
|
56
|
+
# -->
|
|
57
|
+
# Returns the number of elements in this arithmetic sequence if it is a finite
|
|
58
|
+
# sequence. Otherwise, returns `nil`.
|
|
59
|
+
#
|
|
60
|
+
def size: () -> (Integer | Float)
|
|
61
|
+
|
|
62
|
+
# <!--
|
|
63
|
+
# rdoc-file=enumerator.c
|
|
64
|
+
# - aseq.step -> num
|
|
65
|
+
# -->
|
|
66
|
+
# Returns the number that defines the common difference between two adjacent
|
|
67
|
+
# elements in this arithmetic sequence.
|
|
68
|
+
#
|
|
69
|
+
def step: () -> Numeric
|
|
70
|
+
end
|
data/core/enumerator.rbs
CHANGED
|
@@ -137,7 +137,7 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
|
|
|
137
137
|
|
|
138
138
|
# <!--
|
|
139
139
|
# rdoc-file=enumerator.c
|
|
140
|
-
# - Enumerator.produce(initial = nil) { |prev| block } -> enumerator
|
|
140
|
+
# - Enumerator.produce(initial = nil, size: nil) { |prev| block } -> enumerator
|
|
141
141
|
# -->
|
|
142
142
|
# Creates an infinite enumerator from any block, just called over and over. The
|
|
143
143
|
# result of the previous iteration is passed to the next one. If `initial` is
|
|
@@ -169,6 +169,29 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
|
|
|
169
169
|
# Enumerator.produce { scanner.scan(PATTERN) }.slice_after { scanner.eos? }.first
|
|
170
170
|
# # => ["7", "+", "38", "/", "6"]
|
|
171
171
|
#
|
|
172
|
+
# The optional `size` keyword argument specifies the size of the enumerator,
|
|
173
|
+
# which can be retrieved by Enumerator#size. It can be an integer,
|
|
174
|
+
# `Float::INFINITY`, a callable object (such as a lambda), or `nil` to indicate
|
|
175
|
+
# unknown size. When not specified, the size defaults to `Float::INFINITY`.
|
|
176
|
+
#
|
|
177
|
+
# # Infinite enumerator
|
|
178
|
+
# enum = Enumerator.produce(1, size: Float::INFINITY, &:succ)
|
|
179
|
+
# enum.size # => Float::INFINITY
|
|
180
|
+
#
|
|
181
|
+
# # Finite enumerator with known/computable size
|
|
182
|
+
# abs_dir = File.expand_path("./baz") # => "/foo/bar/baz"
|
|
183
|
+
# traverser = Enumerator.produce(abs_dir, size: -> { abs_dir.count("/") + 1 }) {
|
|
184
|
+
# raise StopIteration if it == "/"
|
|
185
|
+
# File.dirname(it)
|
|
186
|
+
# }
|
|
187
|
+
# traverser.size # => 4
|
|
188
|
+
#
|
|
189
|
+
# # Finite enumerator with unknown size
|
|
190
|
+
# calendar = Enumerator.produce(Date.today, size: nil) {
|
|
191
|
+
# it.monday? ? raise(StopIteration) : it + 1
|
|
192
|
+
# }
|
|
193
|
+
# calendar.size # => nil
|
|
194
|
+
#
|
|
172
195
|
def self.produce: [T] () { (T? prev) -> T } -> Enumerator[T, bot]
|
|
173
196
|
| [T] (T initial) { (T prev) -> T } -> Enumerator[T, bot]
|
|
174
197
|
|
|
@@ -446,8 +469,39 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
|
|
|
446
469
|
# loop.size # => Float::INFINITY
|
|
447
470
|
# (1..100).drop_while.size # => nil
|
|
448
471
|
#
|
|
472
|
+
# Note that enumerator size might be inaccurate, and should be rather treated as
|
|
473
|
+
# a hint. For example, there is no check that the size provided to ::new is
|
|
474
|
+
# accurate:
|
|
475
|
+
#
|
|
476
|
+
# e = Enumerator.new(5) { |y| 2.times { y << it} }
|
|
477
|
+
# e.size # => 5
|
|
478
|
+
# e.to_a.size # => 2
|
|
479
|
+
#
|
|
480
|
+
# Another example is an enumerator created by ::produce without a `size`
|
|
481
|
+
# argument. Such enumerators return `Infinity` for size, but this is inaccurate
|
|
482
|
+
# if the passed block raises StopIteration:
|
|
483
|
+
#
|
|
484
|
+
# e = Enumerator.produce(1) { it + 1 }
|
|
485
|
+
# e.size # => Infinity
|
|
486
|
+
#
|
|
487
|
+
# e = Enumerator.produce(1) { it > 3 ? raise(StopIteration) : it + 1 }
|
|
488
|
+
# e.size # => Infinity
|
|
489
|
+
# e.to_a.size # => 4
|
|
490
|
+
#
|
|
449
491
|
def size: () -> (Integer | Float)?
|
|
450
492
|
|
|
493
|
+
# <!--
|
|
494
|
+
# rdoc-file=enumerator.c
|
|
495
|
+
# - e + enum -> enumerator
|
|
496
|
+
# -->
|
|
497
|
+
# Returns an enumerator object generated from this enumerator and a given
|
|
498
|
+
# enumerable.
|
|
499
|
+
#
|
|
500
|
+
# e = (1..3).each + [4, 5]
|
|
501
|
+
# e.to_a #=> [1, 2, 3, 4, 5]
|
|
502
|
+
#
|
|
503
|
+
def +: [Elem2] (::_Each[Elem2]) -> ::Enumerator::Chain[Elem | Elem2]
|
|
504
|
+
|
|
451
505
|
# <!--
|
|
452
506
|
# rdoc-file=enumerator.c
|
|
453
507
|
# - e.with_index(offset = 0) {|(*args), idx| ... }
|
|
@@ -578,6 +632,14 @@ class Enumerator::Lazy[out Elem, out Return = void] < Enumerator[Elem, Return]
|
|
|
578
632
|
# Like Enumerable#compact, but chains operation to be lazy-evaluated.
|
|
579
633
|
#
|
|
580
634
|
def compact: () -> Enumerator::Lazy[Elem, Return]
|
|
635
|
+
|
|
636
|
+
# <!--
|
|
637
|
+
# rdoc-file=enumerator.c
|
|
638
|
+
# - lzy.eager -> enum
|
|
639
|
+
# -->
|
|
640
|
+
# Returns a non-lazy Enumerator converted from the lazy enumerator.
|
|
641
|
+
#
|
|
642
|
+
def eager: () -> ::Enumerator[Elem, Return]
|
|
581
643
|
end
|
|
582
644
|
|
|
583
645
|
# <!-- rdoc-file=enumerator.c -->
|
data/core/errno.rbs
CHANGED
|
@@ -38,6 +38,14 @@
|
|
|
38
38
|
# Errno::ENOENT::Errno # => 2
|
|
39
39
|
# Errno::ENOTCAPABLE::Errno # => 0
|
|
40
40
|
#
|
|
41
|
+
# Each class in Errno can be created with optional messages:
|
|
42
|
+
#
|
|
43
|
+
# Errno::EPIPE.new # => #<Errno::EPIPE: Broken pipe>
|
|
44
|
+
# Errno::EPIPE.new("foo") # => #<Errno::EPIPE: Broken pipe - foo>
|
|
45
|
+
# Errno::EPIPE.new("foo", "here") # => #<Errno::EPIPE: Broken pipe @ here - foo>
|
|
46
|
+
#
|
|
47
|
+
# See SystemCallError.new.
|
|
48
|
+
#
|
|
41
49
|
module Errno
|
|
42
50
|
class NOERROR < SystemCallError
|
|
43
51
|
Errno: 0
|
data/core/errors.rbs
CHANGED
|
@@ -302,9 +302,15 @@ class NameError[T] < StandardError
|
|
|
302
302
|
def receiver: () -> T?
|
|
303
303
|
end
|
|
304
304
|
|
|
305
|
+
# <!-- rdoc-file=error.c -->
|
|
306
|
+
# Raised when matching pattern not found.
|
|
307
|
+
#
|
|
305
308
|
class NoMatchingPatternError < StandardError
|
|
306
309
|
end
|
|
307
310
|
|
|
311
|
+
# <!-- rdoc-file=error.c -->
|
|
312
|
+
# Raised when matching key not found.
|
|
313
|
+
#
|
|
308
314
|
class NoMatchingPatternKeyError[M, K] < NoMatchingPatternError
|
|
309
315
|
# <!--
|
|
310
316
|
# rdoc-file=error.c
|
|
@@ -588,13 +594,34 @@ end
|
|
|
588
594
|
class SystemCallError < StandardError
|
|
589
595
|
# <!--
|
|
590
596
|
# rdoc-file=error.c
|
|
591
|
-
# - SystemCallError.new(msg, errno) -> system_call_error_subclass
|
|
597
|
+
# - SystemCallError.new(msg, errno = nil, func = nil) -> system_call_error_subclass
|
|
592
598
|
# -->
|
|
593
599
|
# If *errno* corresponds to a known system error code, constructs the
|
|
594
600
|
# appropriate Errno class for that error, otherwise constructs a generic
|
|
595
601
|
# SystemCallError object. The error number is subsequently available via the
|
|
596
602
|
# #errno method.
|
|
597
603
|
#
|
|
604
|
+
# If only numeric object is given, it is treated as an Integer *errno*, and
|
|
605
|
+
# *msg* is omitted, otherwise the first argument *msg* is used as the additional
|
|
606
|
+
# error message.
|
|
607
|
+
#
|
|
608
|
+
# SystemCallError.new(Errno::EPIPE::Errno)
|
|
609
|
+
# #=> #<Errno::EPIPE: Broken pipe>
|
|
610
|
+
#
|
|
611
|
+
# SystemCallError.new("foo")
|
|
612
|
+
# #=> #<SystemCallError: unknown error - foo>
|
|
613
|
+
#
|
|
614
|
+
# SystemCallError.new("foo", Errno::EPIPE::Errno)
|
|
615
|
+
# #=> #<Errno::EPIPE: Broken pipe - foo>
|
|
616
|
+
#
|
|
617
|
+
# If *func* is not `nil`, it is appended to the message with "` @ `".
|
|
618
|
+
#
|
|
619
|
+
# SystemCallError.new("foo", Errno::EPIPE::Errno, "here")
|
|
620
|
+
# #=> #<Errno::EPIPE: Broken pipe @ here - foo>
|
|
621
|
+
#
|
|
622
|
+
# A subclass of SystemCallError can also be instantiated via the `new` method of
|
|
623
|
+
# the subclass. See Errno.
|
|
624
|
+
#
|
|
598
625
|
def initialize: (string msg, Integer errno) -> void
|
|
599
626
|
|
|
600
627
|
# <!--
|
data/core/exception.rbs
CHANGED
|
@@ -118,7 +118,7 @@ class Exception
|
|
|
118
118
|
# # String
|
|
119
119
|
# end
|
|
120
120
|
#
|
|
121
|
-
# The value returned by this method
|
|
121
|
+
# The value returned by this method might be adjusted when raising (see
|
|
122
122
|
# Kernel#raise), or during intermediate handling by #set_backtrace.
|
|
123
123
|
#
|
|
124
124
|
# See also #backtrace_locations that provide the same value, as structured
|
|
@@ -447,7 +447,7 @@ class Exception
|
|
|
447
447
|
# * If the value of keyword `order` is `:top` (the default), lists the
|
|
448
448
|
# error message and the innermost backtrace entry first.
|
|
449
449
|
# * If the value of keyword `order` is `:bottom`, lists the error message
|
|
450
|
-
# the
|
|
450
|
+
# the innermost entry last.
|
|
451
451
|
#
|
|
452
452
|
# Example:
|
|
453
453
|
#
|
data/core/fiber.rbs
CHANGED
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
# ## Non-blocking Fibers
|
|
59
59
|
#
|
|
60
60
|
# The concept of *non-blocking fiber* was introduced in Ruby 3.0. A non-blocking
|
|
61
|
-
# fiber, when reaching
|
|
61
|
+
# fiber, when reaching an operation that would normally block the fiber (like
|
|
62
62
|
# `sleep`, or wait for another process or I/O) will yield control to other
|
|
63
63
|
# fibers and allow the *scheduler* to handle blocking and waking up (resuming)
|
|
64
64
|
# this fiber when it can proceed.
|
|
@@ -82,7 +82,8 @@ class Fiber < Object
|
|
|
82
82
|
# -->
|
|
83
83
|
# Returns the value of the fiber storage variable identified by `key`.
|
|
84
84
|
#
|
|
85
|
-
# The `key` must be a symbol, and the value is set by Fiber#[]= or
|
|
85
|
+
# The `key` must be a symbol, and the value is set by Fiber#[]= or
|
|
86
|
+
# Fiber#storage.
|
|
86
87
|
#
|
|
87
88
|
# See also Fiber::[]=.
|
|
88
89
|
#
|
|
@@ -101,6 +102,17 @@ class Fiber < Object
|
|
|
101
102
|
#
|
|
102
103
|
def self.[]=: [A] (Symbol, A) -> A
|
|
103
104
|
|
|
105
|
+
# <!--
|
|
106
|
+
# rdoc-file=cont.c
|
|
107
|
+
# - Fiber.blocking{|fiber| ...} -> result
|
|
108
|
+
# -->
|
|
109
|
+
# Forces the fiber to be blocking for the duration of the block. Returns the
|
|
110
|
+
# result of the block.
|
|
111
|
+
#
|
|
112
|
+
# See the "Non-blocking fibers" section in class docs for details.
|
|
113
|
+
#
|
|
114
|
+
def self.blocking: [T] () { (Fiber) -> T } -> T
|
|
115
|
+
|
|
104
116
|
# <!--
|
|
105
117
|
# rdoc-file=cont.c
|
|
106
118
|
# - Fiber.blocking? -> false or 1
|
|
@@ -392,30 +404,38 @@ class Fiber < Object
|
|
|
392
404
|
|
|
393
405
|
# <!--
|
|
394
406
|
# rdoc-file=cont.c
|
|
395
|
-
# -
|
|
396
|
-
# -
|
|
397
|
-
# - fiber.raise(exception [, string [, array]]) -> obj
|
|
407
|
+
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
|
|
408
|
+
# - raise(message = nil, cause: $!)
|
|
398
409
|
# -->
|
|
399
410
|
# Raises an exception in the fiber at the point at which the last `Fiber.yield`
|
|
400
|
-
# was called.
|
|
401
|
-
#
|
|
402
|
-
#
|
|
403
|
-
#
|
|
404
|
-
#
|
|
405
|
-
#
|
|
406
|
-
#
|
|
407
|
-
#
|
|
408
|
-
#
|
|
409
|
-
#
|
|
410
|
-
#
|
|
411
|
-
#
|
|
411
|
+
# was called.
|
|
412
|
+
#
|
|
413
|
+
# f = Fiber.new {
|
|
414
|
+
# puts "Before the yield"
|
|
415
|
+
# Fiber.yield 1 # -- exception will be raised here
|
|
416
|
+
# puts "After the yield"
|
|
417
|
+
# }
|
|
418
|
+
#
|
|
419
|
+
# p f.resume
|
|
420
|
+
# f.raise "Gotcha"
|
|
421
|
+
#
|
|
422
|
+
# Output
|
|
423
|
+
#
|
|
424
|
+
# Before the first yield
|
|
425
|
+
# 1
|
|
426
|
+
# t.rb:8:in 'Fiber.yield': Gotcha (RuntimeError)
|
|
427
|
+
# from t.rb:8:in 'block in <main>'
|
|
428
|
+
#
|
|
429
|
+
# If the fiber has not been started or has already run to completion, raises
|
|
430
|
+
# `FiberError`. If the fiber is yielding, it is resumed. If it is transferring,
|
|
431
|
+
# it is transferred into. But if it is resuming, raises `FiberError`.
|
|
412
432
|
#
|
|
413
433
|
# Raises `FiberError` if called on a Fiber belonging to another `Thread`.
|
|
414
434
|
#
|
|
415
|
-
# See Kernel#raise for more information.
|
|
435
|
+
# See Kernel#raise for more information on arguments.
|
|
416
436
|
#
|
|
417
|
-
def raise: (?string msg) -> untyped
|
|
418
|
-
| (_Exception, ?string msg, ?Array[string] | Array[Thread::Backtrace::Location] | nil backtrace) -> untyped
|
|
437
|
+
def raise: (?string msg, ?cause: Exception?) -> untyped
|
|
438
|
+
| (_Exception, ?string msg, ?Array[string] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> untyped
|
|
419
439
|
|
|
420
440
|
# <!--
|
|
421
441
|
# rdoc-file=cont.c
|