rbs 3.9.4 → 3.10.2

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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +2 -2
  6. data/.github/workflows/ruby.yml +33 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/CHANGELOG.md +81 -0
  11. data/README.md +38 -1
  12. data/Rakefile +152 -23
  13. data/config.yml +190 -62
  14. data/core/array.rbs +96 -46
  15. data/core/comparable.rbs +13 -6
  16. data/core/complex.rbs +40 -25
  17. data/core/dir.rbs +4 -4
  18. data/core/encoding.rbs +6 -9
  19. data/core/enumerable.rbs +90 -3
  20. data/core/enumerator.rbs +43 -1
  21. data/core/errno.rbs +8 -0
  22. data/core/errors.rbs +28 -1
  23. data/core/exception.rbs +2 -2
  24. data/core/fiber.rbs +29 -20
  25. data/core/file.rbs +49 -19
  26. data/core/file_test.rbs +1 -1
  27. data/core/float.rbs +224 -33
  28. data/core/gc.rbs +417 -281
  29. data/core/hash.rbs +1023 -727
  30. data/core/integer.rbs +104 -63
  31. data/core/io/buffer.rbs +21 -10
  32. data/core/io/wait.rbs +11 -33
  33. data/core/io.rbs +14 -12
  34. data/core/kernel.rbs +61 -51
  35. data/core/marshal.rbs +1 -1
  36. data/core/match_data.rbs +1 -1
  37. data/core/math.rbs +42 -3
  38. data/core/method.rbs +63 -25
  39. data/core/module.rbs +101 -23
  40. data/core/nil_class.rbs +3 -3
  41. data/core/numeric.rbs +25 -17
  42. data/core/object.rbs +3 -3
  43. data/core/object_space.rbs +21 -15
  44. data/core/pathname.rbs +1272 -0
  45. data/core/proc.rbs +30 -24
  46. data/core/process.rbs +2 -2
  47. data/core/ractor.rbs +361 -509
  48. data/core/range.rbs +7 -8
  49. data/core/rational.rbs +56 -34
  50. data/core/rbs/unnamed/argf.rbs +2 -2
  51. data/core/rbs/unnamed/env_class.rbs +1 -1
  52. data/core/rbs/unnamed/random.rbs +4 -2
  53. data/core/regexp.rbs +25 -20
  54. data/core/ruby.rbs +53 -0
  55. data/core/ruby_vm.rbs +6 -4
  56. data/core/rubygems/errors.rbs +3 -70
  57. data/core/rubygems/rubygems.rbs +11 -79
  58. data/core/rubygems/version.rbs +2 -3
  59. data/core/set.rbs +488 -359
  60. data/core/signal.rbs +24 -14
  61. data/core/string.rbs +3164 -1235
  62. data/core/struct.rbs +1 -1
  63. data/core/symbol.rbs +17 -11
  64. data/core/thread.rbs +95 -33
  65. data/core/time.rbs +35 -9
  66. data/core/trace_point.rbs +7 -4
  67. data/core/unbound_method.rbs +14 -6
  68. data/docs/aliases.md +79 -0
  69. data/docs/collection.md +2 -2
  70. data/docs/encoding.md +56 -0
  71. data/docs/gem.md +0 -1
  72. data/docs/sigs.md +3 -3
  73. data/ext/rbs_extension/ast_translation.c +1016 -0
  74. data/ext/rbs_extension/ast_translation.h +37 -0
  75. data/ext/rbs_extension/class_constants.c +155 -0
  76. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  77. data/ext/rbs_extension/compat.h +10 -0
  78. data/ext/rbs_extension/extconf.rb +25 -1
  79. data/ext/rbs_extension/legacy_location.c +317 -0
  80. data/ext/rbs_extension/legacy_location.h +45 -0
  81. data/ext/rbs_extension/main.c +367 -23
  82. data/ext/rbs_extension/rbs_extension.h +6 -21
  83. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  84. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  85. data/include/rbs/ast.h +687 -0
  86. data/include/rbs/defines.h +86 -0
  87. data/include/rbs/lexer.h +199 -0
  88. data/include/rbs/location.h +59 -0
  89. data/include/rbs/parser.h +135 -0
  90. data/include/rbs/string.h +47 -0
  91. data/include/rbs/util/rbs_allocator.h +59 -0
  92. data/include/rbs/util/rbs_assert.h +20 -0
  93. data/include/rbs/util/rbs_buffer.h +83 -0
  94. data/include/rbs/util/rbs_constant_pool.h +6 -67
  95. data/include/rbs/util/rbs_encoding.h +282 -0
  96. data/include/rbs/util/rbs_unescape.h +24 -0
  97. data/include/rbs.h +1 -2
  98. data/lib/rbs/annotate/formatter.rb +3 -13
  99. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  100. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  101. data/lib/rbs/cli/validate.rb +2 -2
  102. data/lib/rbs/cli.rb +1 -1
  103. data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
  104. data/lib/rbs/collection.rb +1 -0
  105. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  106. data/lib/rbs/environment.rb +64 -59
  107. data/lib/rbs/environment_loader.rb +0 -6
  108. data/lib/rbs/errors.rb +1 -1
  109. data/lib/rbs/parser_aux.rb +5 -0
  110. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  111. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  112. data/lib/rbs/subtractor.rb +3 -1
  113. data/lib/rbs/test/type_check.rb +14 -0
  114. data/lib/rbs/types.rb +3 -1
  115. data/lib/rbs/version.rb +1 -1
  116. data/lib/rbs.rb +1 -1
  117. data/lib/rdoc/discover.rb +1 -1
  118. data/lib/rdoc_plugin/parser.rb +3 -3
  119. data/sig/annotate/formatter.rbs +2 -2
  120. data/sig/annotate/rdoc_annotater.rbs +1 -1
  121. data/sig/environment.rbs +57 -6
  122. data/sig/manifest.yaml +0 -1
  123. data/sig/parser.rbs +20 -0
  124. data/sig/resolver/type_name_resolver.rbs +38 -7
  125. data/sig/types.rbs +4 -1
  126. data/src/ast.c +1256 -0
  127. data/src/lexer.c +2956 -0
  128. data/src/lexer.re +147 -0
  129. data/src/lexstate.c +205 -0
  130. data/src/location.c +71 -0
  131. data/src/parser.c +3507 -0
  132. data/src/string.c +41 -0
  133. data/src/util/rbs_allocator.c +165 -0
  134. data/src/util/rbs_assert.c +19 -0
  135. data/src/util/rbs_buffer.c +54 -0
  136. data/src/util/rbs_constant_pool.c +18 -88
  137. data/src/util/rbs_encoding.c +21308 -0
  138. data/src/util/rbs_unescape.c +167 -0
  139. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  140. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  141. data/stdlib/cgi/0/core.rbs +9 -393
  142. data/stdlib/cgi/0/manifest.yaml +1 -0
  143. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  144. data/stdlib/coverage/0/coverage.rbs +3 -1
  145. data/stdlib/date/0/date.rbs +67 -59
  146. data/stdlib/date/0/date_time.rbs +1 -1
  147. data/stdlib/delegate/0/delegator.rbs +10 -7
  148. data/stdlib/erb/0/erb.rbs +737 -347
  149. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  150. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  151. data/stdlib/json/0/json.rbs +68 -48
  152. data/stdlib/net-http/0/net-http.rbs +3 -0
  153. data/stdlib/objspace/0/objspace.rbs +9 -4
  154. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  155. data/stdlib/openssl/0/openssl.rbs +331 -228
  156. data/stdlib/optparse/0/optparse.rbs +3 -3
  157. data/stdlib/pathname/0/pathname.rbs +9 -1379
  158. data/stdlib/psych/0/psych.rbs +3 -3
  159. data/stdlib/rdoc/0/code_object.rbs +2 -2
  160. data/stdlib/rdoc/0/comment.rbs +2 -0
  161. data/stdlib/rdoc/0/options.rbs +76 -0
  162. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  163. data/stdlib/rdoc/0/store.rbs +1 -1
  164. data/stdlib/resolv/0/resolv.rbs +25 -68
  165. data/stdlib/ripper/0/ripper.rbs +5 -2
  166. data/stdlib/singleton/0/singleton.rbs +3 -0
  167. data/stdlib/socket/0/socket.rbs +13 -1
  168. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  169. data/stdlib/stringio/0/stringio.rbs +1176 -85
  170. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  171. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  172. data/stdlib/time/0/time.rbs +1 -1
  173. data/stdlib/timeout/0/timeout.rbs +63 -7
  174. data/stdlib/tsort/0/cyclic.rbs +3 -0
  175. data/stdlib/uri/0/common.rbs +11 -2
  176. data/stdlib/uri/0/file.rbs +1 -1
  177. data/stdlib/uri/0/generic.rbs +17 -16
  178. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  179. data/stdlib/zlib/0/zstream.rbs +1 -0
  180. metadata +44 -18
  181. data/ext/rbs_extension/lexer.c +0 -2728
  182. data/ext/rbs_extension/lexer.h +0 -179
  183. data/ext/rbs_extension/lexer.re +0 -147
  184. data/ext/rbs_extension/lexstate.c +0 -175
  185. data/ext/rbs_extension/location.c +0 -325
  186. data/ext/rbs_extension/location.h +0 -85
  187. data/ext/rbs_extension/parser.c +0 -2982
  188. data/ext/rbs_extension/parser.h +0 -18
  189. data/ext/rbs_extension/parserstate.c +0 -411
  190. data/ext/rbs_extension/parserstate.h +0 -163
  191. data/ext/rbs_extension/unescape.c +0 -32
  192. data/include/rbs/ruby_objs.h +0 -72
  193. data/src/constants.c +0 -153
  194. data/src/ruby_objs.c +0 -799
data/core/integer.rbs CHANGED
@@ -146,9 +146,9 @@ class Integer < Numeric
146
146
 
147
147
  # <!--
148
148
  # rdoc-file=numeric.c
149
- # - self % other -> real_number
149
+ # - self % other -> real_numeric
150
150
  # -->
151
- # Returns `self` modulo `other` as a real number.
151
+ # Returns `self` modulo `other` as a real numeric (Integer, Float, or Rational).
152
152
  #
153
153
  # For integer `n` and real number `r`, these expressions are equivalent:
154
154
  #
@@ -193,13 +193,13 @@ class Integer < Numeric
193
193
 
194
194
  # <!--
195
195
  # rdoc-file=numeric.c
196
- # - self * numeric -> numeric_result
196
+ # - self * other -> numeric
197
197
  # -->
198
- # Performs multiplication:
198
+ # Returns the numeric product of `self` and `other`:
199
199
  #
200
200
  # 4 * 2 # => 8
201
- # 4 * -2 # => -8
202
201
  # -4 * 2 # => -8
202
+ # 4 * -2 # => -8
203
203
  # 4 * 2.0 # => 8.0
204
204
  # 4 * Rational(1, 3) # => (4/3)
205
205
  # 4 * Complex(2, 0) # => (8+0i)
@@ -211,17 +211,47 @@ class Integer < Numeric
211
211
 
212
212
  # <!--
213
213
  # rdoc-file=numeric.c
214
- # - self ** numeric -> numeric_result
214
+ # - self ** exponent -> numeric
215
215
  # -->
216
- # Raises `self` to the power of `numeric`:
217
- #
218
- # 2 ** 3 # => 8
219
- # 2 ** -3 # => (1/8)
220
- # -2 ** 3 # => -8
221
- # -2 ** -3 # => (-1/8)
222
- # 2 ** 3.3 # => 9.849155306759329
223
- # 2 ** Rational(3, 1) # => (8/1)
224
- # 2 ** Complex(3, 0) # => (8+0i)
216
+ # Returns `self` raised to the power `exponent`:
217
+ #
218
+ # # Result for non-negative Integer exponent is Integer.
219
+ # 2 ** 0 # => 1
220
+ # 2 ** 1 # => 2
221
+ # 2 ** 2 # => 4
222
+ # 2 ** 3 # => 8
223
+ # -2 ** 3 # => -8
224
+ # # Result for negative Integer exponent is Rational, not Float.
225
+ # 2 ** -3 # => (1/8)
226
+ # -2 ** -3 # => (-1/8)
227
+ #
228
+ # # Result for Float exponent is Float.
229
+ # 2 ** 0.0 # => 1.0
230
+ # 2 ** 1.0 # => 2.0
231
+ # 2 ** 2.0 # => 4.0
232
+ # 2 ** 3.0 # => 8.0
233
+ # -2 ** 3.0 # => -8.0
234
+ # 2 ** -3.0 # => 0.125
235
+ # -2 ** -3.0 # => -0.125
236
+ #
237
+ # # Result for non-negative Complex exponent is Complex with Integer parts.
238
+ # 2 ** Complex(0, 0) # => (1+0i)
239
+ # 2 ** Complex(1, 0) # => (2+0i)
240
+ # 2 ** Complex(2, 0) # => (4+0i)
241
+ # 2 ** Complex(3, 0) # => (8+0i)
242
+ # -2 ** Complex(3, 0) # => (-8+0i)
243
+ # # Result for negative Complex exponent is Complex with Rational parts.
244
+ # 2 ** Complex(-3, 0) # => ((1/8)+(0/1)*i)
245
+ # -2 ** Complex(-3, 0) # => ((-1/8)+(0/1)*i)
246
+ #
247
+ # # Result for Rational exponent is Rational.
248
+ # 2 ** Rational(0, 1) # => (1/1)
249
+ # 2 ** Rational(1, 1) # => (2/1)
250
+ # 2 ** Rational(2, 1) # => (4/1)
251
+ # 2 ** Rational(3, 1) # => (8/1)
252
+ # -2 ** Rational(3, 1) # => (-8/1)
253
+ # 2 ** Rational(-3, 1) # => (1/8)
254
+ # -2 ** Rational(-3, 1) # => (-1/8)
225
255
  #
226
256
  def **: (Integer) -> Numeric
227
257
  | (Float) -> Numeric
@@ -230,16 +260,20 @@ class Integer < Numeric
230
260
 
231
261
  # <!--
232
262
  # rdoc-file=numeric.c
233
- # - self + numeric -> numeric_result
263
+ # - self + other -> numeric
234
264
  # -->
235
- # Performs addition:
265
+ # Returns the sum of `self` and `other`:
266
+ #
267
+ # 1 + 1 # => 2
268
+ # 1 + -1 # => 0
269
+ # 1 + 0 # => 1
270
+ # 1 + -2 # => -1
271
+ # 1 + Complex(1, 0) # => (2+0i)
272
+ # 1 + Rational(1, 1) # => (2/1)
273
+ #
274
+ # For a computation involving Floats, the result may be inexact (see Float#+):
236
275
  #
237
- # 2 + 2 # => 4
238
- # -2 + 2 # => 0
239
- # -2 + -2 # => -4
240
- # 2 + 2.0 # => 4.0
241
- # 2 + Rational(2, 1) # => (4/1)
242
- # 2 + Complex(2, 0) # => (4+0i)
276
+ # 1 + 3.14 # => 4.140000000000001
243
277
  #
244
278
  def +: (Integer) -> Integer
245
279
  | (Float) -> Float
@@ -250,9 +284,9 @@ class Integer < Numeric
250
284
 
251
285
  # <!--
252
286
  # rdoc-file=numeric.c
253
- # - self - numeric -> numeric_result
287
+ # - self - other -> numeric
254
288
  # -->
255
- # Performs subtraction:
289
+ # Returns the difference of `self` and `other`:
256
290
  #
257
291
  # 4 - 2 # => 2
258
292
  # -4 - 2 # => -6
@@ -268,28 +302,34 @@ class Integer < Numeric
268
302
 
269
303
  # <!--
270
304
  # rdoc-file=numeric.rb
271
- # - -int -> integer
305
+ # - -self -> integer
272
306
  # -->
273
- # Returns `self`, negated.
307
+ # Returns `self`, negated:
308
+ #
309
+ # -1 # => -1
310
+ # -(-1) # => 1
311
+ # -0 # => 0
274
312
  #
275
313
  def -@: () -> Integer
276
314
 
277
315
  # <!--
278
316
  # rdoc-file=numeric.c
279
- # - self / numeric -> numeric_result
317
+ # - self / other -> numeric
280
318
  # -->
281
- # Performs division; for integer `numeric`, truncates the result to an integer:
319
+ # Returns the quotient of `self` and `other`.
320
+ #
321
+ # For integer `other`, truncates the result to an integer:
282
322
  #
283
- # 4 / 3 # => 1
284
- # 4 / -3 # => -2
285
- # -4 / 3 # => -2
286
- # -4 / -3 # => 1
323
+ # 4 / 3 # => 1
324
+ # 4 / -3 # => -2
325
+ # -4 / 3 # => -2
326
+ # -4 / -3 # => 1
287
327
  #
288
- # For other +numeric+, returns non-integer result:
328
+ # For non-integer `other`, returns a non-integer result:
289
329
  #
290
- # 4 / 3.0 # => 1.3333333333333333
291
- # 4 / Rational(3, 1) # => (4/3)
292
- # 4 / Complex(3, 0) # => ((4/3)+0i)
330
+ # 4 / 3.0 # => 1.3333333333333333
331
+ # 4 / Rational(3, 1) # => (4/3)
332
+ # 4 / Complex(3, 0) # => ((4/3)+0i)
293
333
  #
294
334
  def /: (Integer) -> Integer
295
335
  | (Float) -> Float
@@ -300,15 +340,14 @@ class Integer < Numeric
300
340
  # rdoc-file=numeric.c
301
341
  # - self < other -> true or false
302
342
  # -->
303
- # Returns `true` if the value of `self` is less than that of `other`:
343
+ # Returns whether the value of `self` is less than the value of `other`; `other`
344
+ # must be numeric, but may not be Complex:
304
345
  #
305
- # 1 < 0 # => false
306
- # 1 < 1 # => false
307
- # 1 < 2 # => true
308
- # 1 < 0.5 # => false
309
- # 1 < Rational(1, 2) # => false
310
- #
311
- # Raises an exception if the comparison cannot be made.
346
+ # 1 < 0 # => false
347
+ # 1 < 1 # => false
348
+ # 1 < 2 # => true
349
+ # 1 < 0.5 # => false
350
+ # 1 < Rational(1, 2) # => false
312
351
  #
313
352
  def <: (Numeric) -> bool
314
353
 
@@ -331,44 +370,46 @@ class Integer < Numeric
331
370
 
332
371
  # <!--
333
372
  # rdoc-file=numeric.c
334
- # - self <= real -> true or false
373
+ # - self <= other -> true or false
335
374
  # -->
336
- # Returns `true` if the value of `self` is less than or equal to that of
337
- # `other`:
375
+ # Returns whether the value of `self` is less than or equal to the value of
376
+ # `other`; `other` must be numeric, but may not be Complex:
338
377
  #
339
- # 1 <= 0 # => false
340
- # 1 <= 1 # => true
341
- # 1 <= 2 # => true
342
- # 1 <= 0.5 # => false
343
- # 1 <= Rational(1, 2) # => false
378
+ # 1 <= 0 # => false
379
+ # 1 <= 1 # => true
380
+ # 1 <= 2 # => true
381
+ # 1 <= 0.5 # => false
382
+ # 1 <= Rational(1, 2) # => false
344
383
  #
345
- # Raises an exception if the comparison cannot be made.
384
+ # Raises an exception if the comparison cannot be made.
346
385
  #
347
386
  def <=: (Numeric) -> bool
348
387
 
349
388
  # <!--
350
389
  # rdoc-file=numeric.c
351
- # - self <=> other -> -1, 0, +1, or nil
390
+ # - self <=> other -> -1, 0, 1, or nil
352
391
  # -->
392
+ # Compares `self` and `other`.
393
+ #
353
394
  # Returns:
354
395
  #
355
- # * -1, if `self` is less than `other`.
356
- # * 0, if `self` is equal to `other`.
357
- # * 1, if `self` is greater then `other`.
396
+ # * `-1`, if `self` is less than `other`.
397
+ # * `0`, if `self` is equal to `other`.
398
+ # * `1`, if `self` is greater then `other`.
358
399
  # * `nil`, if `self` and `other` are incomparable.
359
400
  #
360
401
  # Examples:
361
402
  #
362
403
  # 1 <=> 2 # => -1
363
404
  # 1 <=> 1 # => 0
364
- # 1 <=> 0 # => 1
365
- # 1 <=> 'foo' # => nil
366
- #
367
405
  # 1 <=> 1.0 # => 0
368
406
  # 1 <=> Rational(1, 1) # => 0
369
407
  # 1 <=> Complex(1, 0) # => 0
408
+ # 1 <=> 0 # => 1
409
+ # 1 <=> 'foo' # => nil
370
410
  #
371
- # This method is the basis for comparisons in module Comparable.
411
+ # Class Integer includes module Comparable, each of whose methods uses
412
+ # Integer#<=> for comparison.
372
413
  #
373
414
  def <=>: (Integer | Rational) -> Integer
374
415
  | (untyped) -> Integer?
@@ -955,7 +996,7 @@ class Integer < Numeric
955
996
  def magnitude: () -> Integer
956
997
 
957
998
  # <!-- rdoc-file=numeric.c -->
958
- # Returns `self` modulo `other` as a real number.
999
+ # Returns `self` modulo `other` as a real numeric (Integer, Float, or Rational).
959
1000
  #
960
1001
  # For integer `n` and real number `r`, these expressions are equivalent:
961
1002
  #
data/core/io/buffer.rbs CHANGED
@@ -64,9 +64,9 @@ class IO
64
64
  #
65
65
  # File.write('test.txt', 'test data')
66
66
  # # => 9
67
- # buffer = IO::Buffer.map(File.open('test.txt'))
67
+ # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
68
68
  # # =>
69
- # # #<IO::Buffer 0x00007f3f0768c000+9 MAPPED IMMUTABLE>
69
+ # # #<IO::Buffer 0x00007f3f0768c000+9 EXTERNAL MAPPED FILE SHARED READONLY>
70
70
  # # ...
71
71
  # buffer.get_string(5, 2) # read 2 bytes, starting from offset 5
72
72
  # # => "da"
@@ -113,7 +113,7 @@ class IO
113
113
  # buffer.get_string(0, 1)
114
114
  # # => "t"
115
115
  # string
116
- # # => "best"
116
+ # # => "test"
117
117
  #
118
118
  # buffer.resize(100)
119
119
  # # in `resize': Cannot resize external buffer! (IO::Buffer::AccessError)
@@ -131,18 +131,25 @@ class IO
131
131
  # - IO::Buffer.map(file, [size, [offset, [flags]]]) -> io_buffer
132
132
  # -->
133
133
  # Create an IO::Buffer for reading from `file` by memory-mapping the file.
134
- # `file_io` should be a `File` instance, opened for reading.
134
+ # `file` should be a `File` instance, opened for reading or reading and writing.
135
+ #
136
+ # Optional `size` and `offset` of mapping can be specified. Trying to map an
137
+ # empty file or specify `size` of 0 will raise an error. Valid values for
138
+ # `offset` are system-dependent.
135
139
  #
136
- # Optional `size` and `offset` of mapping can be specified.
140
+ # By default, the buffer is writable and expects the file to be writable. It is
141
+ # also shared, so several processes can use the same mapping.
137
142
  #
138
- # By default, the buffer would be immutable (read only); to create a writable
139
- # mapping, you need to open a file in read-write mode, and explicitly pass
140
- # `flags` argument without IO::Buffer::IMMUTABLE.
143
+ # You can pass IO::Buffer::READONLY in `flags` argument to make a read-only
144
+ # buffer; this allows to work with files opened only for reading. Specifying
145
+ # IO::Buffer::PRIVATE in `flags` creates a private mapping, which will not
146
+ # impact other processes or the underlying file. It also allows updating a
147
+ # buffer created from a read-only file.
141
148
  #
142
149
  # File.write('test.txt', 'test')
143
150
  #
144
151
  # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
145
- # # => #<IO::Buffer 0x00000001014a0000+4 MAPPED READONLY>
152
+ # # => #<IO::Buffer 0x00000001014a0000+4 EXTERNAL MAPPED FILE SHARED READONLY>
146
153
  #
147
154
  # buffer.readonly? # => true
148
155
  #
@@ -150,7 +157,7 @@ class IO
150
157
  # # => "test"
151
158
  #
152
159
  # buffer.set_string('b', 0)
153
- # # `set_string': Buffer is not writable! (IO::Buffer::AccessError)
160
+ # # 'IO::Buffer#set_string': Buffer is not writable! (IO::Buffer::AccessError)
154
161
  #
155
162
  # # create read/write mapping: length 4 bytes, offset 0, flags 0
156
163
  # buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 4, 0)
@@ -382,6 +389,10 @@ class IO
382
389
  # * `:U64`: unsigned integer, 8 bytes, big-endian
383
390
  # * `:s64`: signed integer, 8 bytes, little-endian
384
391
  # * `:S64`: signed integer, 8 bytes, big-endian
392
+ # * `:u128`: unsigned integer, 16 bytes, little-endian
393
+ # * `:U128`: unsigned integer, 16 bytes, big-endian
394
+ # * `:s128`: signed integer, 16 bytes, little-endian
395
+ # * `:S128`: signed integer, 16 bytes, big-endian
385
396
  # * `:f32`: float, 4 bytes, little-endian
386
397
  # * `:F32`: float, 4 bytes, big-endian
387
398
  # * `:f64`: double, 8 bytes, little-endian
data/core/io/wait.rbs CHANGED
@@ -1,30 +1,9 @@
1
1
  %a{annotate:rdoc:skip}
2
2
  class IO
3
3
  # <!--
4
- # rdoc-file=ext/io/wait/wait.c
5
- # - io.nread -> int
6
- # -->
7
- # Returns number of bytes that can be read without blocking. Returns zero if no
8
- # information available.
9
- #
10
- # You must require 'io/wait' to use this method.
11
- #
12
- def nread: () -> Integer
13
-
14
- # <!--
15
- # rdoc-file=ext/io/wait/wait.c
16
- # - io.ready? -> truthy or falsy
17
- # -->
18
- # Returns a truthy value if input available without blocking, or a falsy value.
19
- #
20
- # You must require 'io/wait' to use this method.
21
- #
22
- def ready?: () -> boolish
23
-
24
- # <!--
25
- # rdoc-file=ext/io/wait/wait.c
4
+ # rdoc-file=io.c
26
5
  # - io.wait(events, timeout) -> event mask, false or nil
27
- # - io.wait(timeout = nil, mode = :read) -> self, true, or false
6
+ # - io.wait(*event_symbols[, timeout]) -> self, true, or false
28
7
  # -->
29
8
  # Waits until the IO becomes ready for the specified events and returns the
30
9
  # subset of events that become ready, or a falsy value when times out.
@@ -32,11 +11,14 @@ class IO
32
11
  # The events can be a bit mask of `IO::READABLE`, `IO::WRITABLE` or
33
12
  # `IO::PRIORITY`.
34
13
  #
35
- # Returns a truthy value immediately when buffered data is available.
36
- #
37
- # Optional parameter `mode` is one of `:read`, `:write`, or `:read_write`.
14
+ # Returns an event mask (truthy value) immediately when buffered data is
15
+ # available.
38
16
  #
39
- # You must require 'io/wait' to use this method.
17
+ # The second form: if one or more event symbols (`:read`, `:write`, or
18
+ # `:read_write`) are passed, the event mask is the bit OR of the bitmask
19
+ # corresponding to those symbols. In this form, `timeout` is optional, the
20
+ # order of the arguments is arbitrary, and returns `io` if any of the events is
21
+ # ready.
40
22
  #
41
23
  def wait: (Integer events, ?Time::_Timeout timeout) -> (Integer | false | nil)
42
24
  | (?Time::_Timeout? timeout, *wait_mode mode) -> (self | true | false)
@@ -44,7 +26,7 @@ class IO
44
26
  type wait_mode = :read | :r | :readable | :write | :w | :writable | :read_write | :rw | :readable_writable
45
27
 
46
28
  # <!--
47
- # rdoc-file=ext/io/wait/wait.c
29
+ # rdoc-file=io.c
48
30
  # - io.wait_readable -> truthy or falsy
49
31
  # - io.wait_readable(timeout) -> truthy or falsy
50
32
  # -->
@@ -52,19 +34,15 @@ class IO
52
34
  # times out. Returns a truthy value immediately when buffered data is
53
35
  # available.
54
36
  #
55
- # You must require 'io/wait' to use this method.
56
- #
57
37
  def wait_readable: (?Time::_Timeout? timeout) -> boolish
58
38
 
59
39
  # <!--
60
- # rdoc-file=ext/io/wait/wait.c
40
+ # rdoc-file=io.c
61
41
  # - io.wait_writable -> truthy or falsy
62
42
  # - io.wait_writable(timeout) -> truthy or falsy
63
43
  # -->
64
44
  # Waits until IO is writable and returns a truthy value or a falsy value when
65
45
  # times out.
66
46
  #
67
- # You must require 'io/wait' to use this method.
68
- #
69
47
  def wait_writable: (?Time::_Timeout? timeout) -> boolish
70
48
  end
data/core/io.rbs CHANGED
@@ -1373,7 +1373,7 @@ class IO < Object
1373
1373
  # Formats and writes `objects` to the stream.
1374
1374
  #
1375
1375
  # For details on `format_string`, see [Format
1376
- # Specifications](rdoc-ref:format_specifications.rdoc).
1376
+ # Specifications](rdoc-ref:language/format_specifications.rdoc).
1377
1377
  #
1378
1378
  def printf: (String format_string, *untyped objects) -> nil
1379
1379
 
@@ -2276,7 +2276,7 @@ class IO < Object
2276
2276
  #
2277
2277
  # When called from class IO (but not subclasses of IO), this method has
2278
2278
  # potential security vulnerabilities if called with untrusted input; see
2279
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2279
+ # [Command Injection](rdoc-ref:security/command_injection.rdoc).
2280
2280
  #
2281
2281
  def self.binread: (String name, ?Integer? length, ?Integer offset) -> String
2282
2282
 
@@ -2289,7 +2289,7 @@ class IO < Object
2289
2289
  #
2290
2290
  # When called from class IO (but not subclasses of IO), this method has
2291
2291
  # potential security vulnerabilities if called with untrusted input; see
2292
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2292
+ # [Command Injection](rdoc-ref:security/command_injection.rdoc).
2293
2293
  #
2294
2294
  def self.binwrite: (String name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
2295
2295
 
@@ -2354,15 +2354,16 @@ class IO < Object
2354
2354
  # connected to a new stream `io`.
2355
2355
  #
2356
2356
  # This method has potential security vulnerabilities if called with untrusted
2357
- # input; see [Command Injection](rdoc-ref:command_injection.rdoc).
2357
+ # input; see [Command Injection](rdoc-ref:security/command_injection.rdoc).
2358
2358
  #
2359
2359
  # If no block is given, returns the new stream, which depending on given `mode`
2360
2360
  # may be open for reading, writing, or both. The stream should be explicitly
2361
2361
  # closed (eventually) to avoid resource leaks.
2362
2362
  #
2363
2363
  # If a block is given, the stream is passed to the block (again, open for
2364
- # reading, writing, or both); when the block exits, the stream is closed, and
2365
- # the block's value is assigned to global variable `$?` and returned.
2364
+ # reading, writing, or both); when the block exits, the stream is closed, the
2365
+ # block's value is returned, and the global variable `$?` is set to the child's
2366
+ # exit status.
2366
2367
  #
2367
2368
  # Optional argument `mode` may be any valid IO mode. See [Access
2368
2369
  # Modes](rdoc-ref:File@Access+Modes).
@@ -2391,7 +2392,7 @@ class IO < Object
2391
2392
  # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2392
2393
  # * Options for Kernel#spawn.
2393
2394
  #
2394
- # **Forked \Process**
2395
+ # **Forked Process**
2395
2396
  #
2396
2397
  # When argument `cmd` is the 1-character string `'-'`, causes the process to
2397
2398
  # fork:
@@ -2528,7 +2529,7 @@ class IO < Object
2528
2529
  #
2529
2530
  # When called from class IO (but not subclasses of IO), this method has
2530
2531
  # potential security vulnerabilities if called with untrusted input; see
2531
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2532
+ # [Command Injection](rdoc-ref:security/command_injection.rdoc).
2532
2533
  #
2533
2534
  # The first argument must be a string that is the path to a file.
2534
2535
  #
@@ -2685,7 +2686,7 @@ class IO < Object
2685
2686
  #
2686
2687
  # When called from class IO (but not subclasses of IO), this method has
2687
2688
  # potential security vulnerabilities if called with untrusted input; see
2688
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2689
+ # [Command Injection](rdoc-ref:security/command_injection.rdoc).
2689
2690
  #
2690
2691
  # The first argument must be a string that is the path to a file.
2691
2692
  #
@@ -2728,7 +2729,7 @@ class IO < Object
2728
2729
  #
2729
2730
  # When called from class IO (but not subclasses of IO), this method has
2730
2731
  # potential security vulnerabilities if called with untrusted input; see
2731
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2732
+ # [Command Injection](rdoc-ref:security/command_injection.rdoc).
2732
2733
  #
2733
2734
  # The first argument must be a string that is the path to a file.
2734
2735
  #
@@ -2785,7 +2786,8 @@ class IO < Object
2785
2786
  # IO objects.
2786
2787
  #
2787
2788
  # Argument `timeout` is a numeric value (such as integer or float) timeout
2788
- # interval in seconds.
2789
+ # interval in seconds. `timeout` can also be `nil` or `Float::INFINITY`. `nil`
2790
+ # and `Float::INFINITY` means no timeout.
2789
2791
  #
2790
2792
  # The method monitors the IO objects given in all three arrays, waiting for some
2791
2793
  # to be ready; returns a 3-element array whose elements are:
@@ -2952,7 +2954,7 @@ class IO < Object
2952
2954
  #
2953
2955
  # When called from class IO (but not subclasses of IO), this method has
2954
2956
  # potential security vulnerabilities if called with untrusted input; see
2955
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2957
+ # [Command Injection](rdoc-ref:security/command_injection.rdoc).
2956
2958
  #
2957
2959
  # The first argument must be a string that is the path to a file.
2958
2960
  #