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.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +11 -8
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/dependabot.yml +1 -1
  7. data/.github/workflows/ruby.yml +17 -34
  8. data/.github/workflows/typecheck.yml +2 -2
  9. data/.github/workflows/valgrind.yml +42 -0
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/README.md +1 -1
  13. data/Rakefile +32 -5
  14. data/config.yml +46 -0
  15. data/core/array.rbs +96 -46
  16. data/core/binding.rbs +0 -2
  17. data/core/builtin.rbs +2 -2
  18. data/core/comparable.rbs +13 -6
  19. data/core/complex.rbs +55 -41
  20. data/core/dir.rbs +4 -4
  21. data/core/encoding.rbs +7 -10
  22. data/core/enumerable.rbs +90 -3
  23. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  24. data/core/enumerator.rbs +63 -1
  25. data/core/errno.rbs +8 -0
  26. data/core/errors.rbs +28 -1
  27. data/core/exception.rbs +2 -2
  28. data/core/fiber.rbs +40 -20
  29. data/core/file.rbs +108 -78
  30. data/core/file_test.rbs +1 -1
  31. data/core/float.rbs +225 -69
  32. data/core/gc.rbs +417 -281
  33. data/core/hash.rbs +1023 -727
  34. data/core/integer.rbs +104 -110
  35. data/core/io/buffer.rbs +21 -10
  36. data/core/io/wait.rbs +11 -33
  37. data/core/io.rbs +82 -19
  38. data/core/kernel.rbs +70 -59
  39. data/core/marshal.rbs +1 -1
  40. data/core/match_data.rbs +1 -1
  41. data/core/math.rbs +42 -3
  42. data/core/method.rbs +63 -27
  43. data/core/module.rbs +103 -26
  44. data/core/nil_class.rbs +3 -3
  45. data/core/numeric.rbs +43 -35
  46. data/core/object.rbs +3 -3
  47. data/core/object_space.rbs +21 -15
  48. data/core/pathname.rbs +1272 -0
  49. data/core/proc.rbs +30 -25
  50. data/core/process.rbs +4 -2
  51. data/core/ractor.rbs +361 -509
  52. data/core/random.rbs +17 -0
  53. data/core/range.rbs +113 -16
  54. data/core/rational.rbs +56 -85
  55. data/core/rbs/unnamed/argf.rbs +2 -2
  56. data/core/rbs/unnamed/env_class.rbs +1 -1
  57. data/core/rbs/unnamed/random.rbs +4 -113
  58. data/core/regexp.rbs +25 -20
  59. data/core/ruby.rbs +53 -0
  60. data/core/ruby_vm.rbs +6 -4
  61. data/core/rubygems/errors.rbs +3 -70
  62. data/core/rubygems/rubygems.rbs +11 -79
  63. data/core/rubygems/version.rbs +2 -3
  64. data/core/set.rbs +488 -359
  65. data/core/signal.rbs +24 -14
  66. data/core/string.rbs +3171 -1241
  67. data/core/struct.rbs +1 -1
  68. data/core/symbol.rbs +17 -11
  69. data/core/thread.rbs +95 -33
  70. data/core/time.rbs +35 -9
  71. data/core/trace_point.rbs +7 -4
  72. data/core/unbound_method.rbs +14 -6
  73. data/docs/aliases.md +79 -0
  74. data/docs/collection.md +2 -2
  75. data/docs/encoding.md +56 -0
  76. data/docs/gem.md +0 -1
  77. data/docs/inline.md +470 -0
  78. data/docs/sigs.md +3 -3
  79. data/docs/syntax.md +33 -4
  80. data/docs/type_fingerprint.md +21 -0
  81. data/exe/rbs +1 -1
  82. data/ext/rbs_extension/ast_translation.c +77 -3
  83. data/ext/rbs_extension/ast_translation.h +3 -0
  84. data/ext/rbs_extension/class_constants.c +8 -2
  85. data/ext/rbs_extension/class_constants.h +4 -0
  86. data/ext/rbs_extension/extconf.rb +5 -1
  87. data/ext/rbs_extension/legacy_location.c +5 -5
  88. data/ext/rbs_extension/main.c +37 -20
  89. data/include/rbs/ast.h +85 -38
  90. data/include/rbs/defines.h +27 -0
  91. data/include/rbs/lexer.h +30 -11
  92. data/include/rbs/parser.h +6 -6
  93. data/include/rbs/string.h +0 -2
  94. data/include/rbs/util/rbs_allocator.h +34 -13
  95. data/include/rbs/util/rbs_assert.h +12 -1
  96. data/include/rbs/util/rbs_encoding.h +2 -0
  97. data/include/rbs/util/rbs_unescape.h +2 -1
  98. data/lib/rbs/ast/annotation.rb +1 -1
  99. data/lib/rbs/ast/comment.rb +1 -1
  100. data/lib/rbs/ast/declarations.rb +10 -10
  101. data/lib/rbs/ast/members.rb +14 -14
  102. data/lib/rbs/ast/ruby/annotations.rb +137 -0
  103. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  104. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  105. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  106. data/lib/rbs/ast/ruby/members.rb +159 -1
  107. data/lib/rbs/ast/type_param.rb +24 -4
  108. data/lib/rbs/buffer.rb +20 -15
  109. data/lib/rbs/cli/diff.rb +16 -15
  110. data/lib/rbs/cli/validate.rb +38 -51
  111. data/lib/rbs/cli.rb +52 -19
  112. data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
  113. data/lib/rbs/collection/sources/git.rb +1 -0
  114. data/lib/rbs/definition.rb +1 -1
  115. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  116. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  117. data/lib/rbs/definition_builder.rb +91 -2
  118. data/lib/rbs/diff.rb +7 -1
  119. data/lib/rbs/environment.rb +227 -74
  120. data/lib/rbs/environment_loader.rb +0 -6
  121. data/lib/rbs/errors.rb +27 -7
  122. data/lib/rbs/inline_parser.rb +341 -5
  123. data/lib/rbs/location_aux.rb +1 -1
  124. data/lib/rbs/locator.rb +5 -1
  125. data/lib/rbs/method_type.rb +5 -3
  126. data/lib/rbs/parser_aux.rb +2 -2
  127. data/lib/rbs/prototype/rb.rb +2 -2
  128. data/lib/rbs/prototype/rbi.rb +2 -0
  129. data/lib/rbs/prototype/runtime.rb +8 -0
  130. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  131. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  132. data/lib/rbs/subtractor.rb +3 -1
  133. data/lib/rbs/test/type_check.rb +16 -2
  134. data/lib/rbs/type_name.rb +1 -1
  135. data/lib/rbs/types.rb +27 -27
  136. data/lib/rbs/validator.rb +2 -2
  137. data/lib/rbs/version.rb +1 -1
  138. data/lib/rbs.rb +1 -1
  139. data/lib/rdoc/discover.rb +1 -1
  140. data/lib/rdoc_plugin/parser.rb +1 -1
  141. data/rbs.gemspec +3 -2
  142. data/schema/typeParam.json +17 -1
  143. data/sig/ast/ruby/annotations.rbs +124 -0
  144. data/sig/ast/ruby/comment_block.rbs +8 -0
  145. data/sig/ast/ruby/declarations.rbs +102 -4
  146. data/sig/ast/ruby/members.rbs +87 -1
  147. data/sig/cli/diff.rbs +5 -11
  148. data/sig/cli/validate.rbs +13 -4
  149. data/sig/cli.rbs +18 -18
  150. data/sig/definition.rbs +6 -1
  151. data/sig/environment.rbs +70 -12
  152. data/sig/errors.rbs +13 -6
  153. data/sig/inline_parser.rbs +39 -2
  154. data/sig/locator.rbs +0 -2
  155. data/sig/manifest.yaml +0 -1
  156. data/sig/method_builder.rbs +3 -1
  157. data/sig/method_types.rbs +1 -1
  158. data/sig/parser.rbs +16 -2
  159. data/sig/resolver/type_name_resolver.rbs +35 -7
  160. data/sig/source.rbs +3 -3
  161. data/sig/type_param.rbs +13 -8
  162. data/sig/types.rbs +4 -4
  163. data/src/ast.c +80 -1
  164. data/src/lexer.c +1392 -1313
  165. data/src/lexer.re +3 -0
  166. data/src/lexstate.c +58 -37
  167. data/src/location.c +4 -4
  168. data/src/parser.c +412 -145
  169. data/src/string.c +0 -48
  170. data/src/util/rbs_allocator.c +89 -71
  171. data/src/util/rbs_assert.c +1 -1
  172. data/src/util/rbs_buffer.c +2 -2
  173. data/src/util/rbs_constant_pool.c +10 -10
  174. data/src/util/rbs_encoding.c +4 -8
  175. data/src/util/rbs_unescape.c +56 -20
  176. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  177. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  178. data/stdlib/cgi/0/core.rbs +9 -393
  179. data/stdlib/cgi/0/manifest.yaml +1 -0
  180. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  181. data/stdlib/coverage/0/coverage.rbs +3 -1
  182. data/stdlib/date/0/date.rbs +67 -59
  183. data/stdlib/date/0/date_time.rbs +1 -1
  184. data/stdlib/delegate/0/delegator.rbs +10 -7
  185. data/stdlib/digest/0/digest.rbs +110 -0
  186. data/stdlib/erb/0/erb.rbs +737 -347
  187. data/stdlib/fileutils/0/fileutils.rbs +20 -14
  188. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  189. data/stdlib/json/0/json.rbs +82 -28
  190. data/stdlib/net-http/0/net-http.rbs +3 -0
  191. data/stdlib/objspace/0/objspace.rbs +9 -27
  192. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  193. data/stdlib/open3/0/open3.rbs +459 -1
  194. data/stdlib/openssl/0/openssl.rbs +331 -228
  195. data/stdlib/optparse/0/optparse.rbs +8 -3
  196. data/stdlib/pathname/0/pathname.rbs +9 -1379
  197. data/stdlib/psych/0/psych.rbs +4 -4
  198. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  199. data/stdlib/rdoc/0/code_object.rbs +2 -1
  200. data/stdlib/rdoc/0/parser.rbs +1 -1
  201. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  202. data/stdlib/rdoc/0/store.rbs +1 -1
  203. data/stdlib/resolv/0/resolv.rbs +25 -68
  204. data/stdlib/ripper/0/ripper.rbs +2 -2
  205. data/stdlib/securerandom/0/manifest.yaml +2 -0
  206. data/stdlib/securerandom/0/securerandom.rbs +6 -19
  207. data/stdlib/singleton/0/singleton.rbs +3 -0
  208. data/stdlib/socket/0/socket.rbs +13 -1
  209. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  210. data/stdlib/stringio/0/stringio.rbs +1176 -85
  211. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  212. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  213. data/stdlib/time/0/time.rbs +1 -1
  214. data/stdlib/timeout/0/timeout.rbs +63 -7
  215. data/stdlib/tsort/0/cyclic.rbs +3 -0
  216. data/stdlib/uri/0/common.rbs +16 -2
  217. data/stdlib/uri/0/file.rbs +1 -1
  218. data/stdlib/uri/0/generic.rbs +24 -16
  219. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  220. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  221. data/stdlib/zlib/0/gzip_writer.rbs +1 -1
  222. data/stdlib/zlib/0/zstream.rbs +1 -0
  223. 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: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>
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(*patterns, flags: 0, base: nil, sort: true) -> array
481
- # - Dir.glob(*patterns, flags: 0, base: nil, sort: true) {|entry_name| ... } -> nil
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: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>
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
- # Returns the name of the encoding.
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
- # rdoc-file=encoding.c
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 ==: (self) -> bool
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
- | () -> Encoding::UndefinedConversionError?
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 returned
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 chuck:
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 migth be adjusted when raising (see
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 the innermost entry last.
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 a operation that would normally block the fiber (like
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 Fiber#store.
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
- # - fiber.raise -> obj
396
- # - fiber.raise(string) -> obj
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. If the fiber has not been started or has already run to
401
- # completion, raises `FiberError`. If the fiber is yielding, it is resumed. If
402
- # it is transferring, it is transferred into. But if it is resuming, raises
403
- # `FiberError`.
404
- #
405
- # With no arguments, raises a `RuntimeError`. With a single `String` argument,
406
- # raises a `RuntimeError` with the string as a message. Otherwise, the first
407
- # parameter should be the name of an `Exception` class (or an object that
408
- # returns an `Exception` object when sent an `exception` message). The optional
409
- # second parameter sets the message associated with the exception, and the third
410
- # parameter is an array of callback information. Exceptions are caught by the
411
- # `rescue` clause of `begin...end` blocks.
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