rbs 3.0.0.dev.2 → 3.0.0.dev.3

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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
data/core/io/buffer.rbs CHANGED
@@ -25,11 +25,11 @@ class IO
25
25
  # Empty buffer:
26
26
  #
27
27
  # buffer = IO::Buffer.new(8) # create empty 8-byte buffer
28
- # # =>
28
+ # # =>
29
29
  # # #<IO::Buffer 0x0000555f5d1a5c50+8 INTERNAL>
30
30
  # # ...
31
31
  # buffer
32
- # # =>
32
+ # # =>
33
33
  # # <IO::Buffer 0x0000555f5d156ab0+8 INTERNAL>
34
34
  # # 0x00000000 00 00 00 00 00 00 00 00
35
35
  # buffer.set_string('test', 2) # put there bytes of the "test" string, starting from offset 2
@@ -40,12 +40,12 @@ class IO
40
40
  # Buffer from string:
41
41
  #
42
42
  # string = 'data'
43
- # buffer = IO::Buffer.for(str)
44
- # # =>
43
+ # buffer = IO::Buffer.for(string)
44
+ # # =>
45
45
  # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
46
46
  # # ...
47
47
  # buffer
48
- # # =>
48
+ # # =>
49
49
  # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
50
50
  # # 0x00000000 64 61 74 61 data
51
51
  #
@@ -54,7 +54,7 @@ class IO
54
54
  # buffer.set_string('---', 1) # write content, starting from offset 1
55
55
  # # => 3
56
56
  # buffer
57
- # # =>
57
+ # # =>
58
58
  # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
59
59
  # # 0x00000000 64 2d 2d 2d d---
60
60
  # string # original string changed, too
@@ -65,7 +65,7 @@ class IO
65
65
  # File.write('test.txt', 'test data')
66
66
  # # => 9
67
67
  # buffer = IO::Buffer.map(File.open('test.txt'))
68
- # # =>
68
+ # # =>
69
69
  # # #<IO::Buffer 0x00007f3f0768c000+9 MAPPED IMMUTABLE>
70
70
  # # ...
71
71
  # buffer.get_string(5, 2) # read 2 bytes, starting from offset 5
@@ -135,6 +135,8 @@ class IO
135
135
  # mapping, you need to open a file in read-write mode, and explicitly pass
136
136
  # `flags` argument without IO::Buffer::IMMUTABLE.
137
137
  #
138
+ # Example:
139
+ #
138
140
  # File.write('test.txt', 'test')
139
141
  #
140
142
  # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
@@ -214,7 +216,7 @@ class IO
214
216
  # using `memcpy`. For copying String instances, see #set_string.
215
217
  #
216
218
  # buffer = IO::Buffer.new(32)
217
- # # =>
219
+ # # =>
218
220
  # # #<IO::Buffer 0x0000555f5ca22520+32 INTERNAL>
219
221
  # # 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
220
222
  # # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
@@ -222,7 +224,7 @@ class IO
222
224
  # buffer.copy(IO::Buffer.for("test"), 8)
223
225
  # # => 4 -- size of data copied
224
226
  # buffer
225
- # # =>
227
+ # # =>
226
228
  # # #<IO::Buffer 0x0000555f5cf8fe40+32 INTERNAL>
227
229
  # # 0x00000000 00 00 00 00 00 00 00 00 74 65 73 74 00 00 00 00 ........test....
228
230
  # # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
@@ -231,7 +233,7 @@ class IO
231
233
  #
232
234
  # string= "data: "
233
235
  # # => "data: "
234
- # buffer = IO::Buffer.for(str)
236
+ # buffer = IO::Buffer.for(string)
235
237
  # buffer.copy(IO::Buffer.for("test"), 5)
236
238
  # # => 4
237
239
  # string
@@ -247,7 +249,7 @@ class IO
247
249
  # See ::map for details of creation of mutable file mappings, this will work:
248
250
  #
249
251
  # buffer = IO::Buffer.map(File.open('test.txt', 'r+'))
250
- # buffer.copy("boom", 0)
252
+ # buffer.copy(IO::Buffer.for("boom"), 0)
251
253
  # # => 4
252
254
  # File.read('test.txt')
253
255
  # # => "boom"
@@ -256,29 +258,31 @@ class IO
256
258
  # fail:
257
259
  #
258
260
  # buffer = IO::Buffer.new(2)
259
- # buffer.copy('test', 0)
261
+ # buffer.copy(IO::Buffer.for('test'), 0)
260
262
  # # in `copy': Specified offset+length exceeds source size! (ArgumentError)
261
263
  #
262
264
  def copy: (Buffer source, ?Integer offset, ?Integer length, ?Integer source_offset) -> Integer
263
265
 
264
266
  # <!--
265
267
  # rdoc-file=io_buffer.c
266
- # - external? -> true or false
268
+ # - empty? -> true or false
267
269
  # -->
268
- # If the buffer is _external_, meaning it references from memory which is not
269
- # allocated or mapped by the buffer itself.
270
- #
271
- # A buffer created using ::for has an external reference to the string's
272
- # memory.
273
- #
274
- # External buffer can't be resized.
270
+ # If the buffer has 0 size: it is created by ::new with size 0, or with ::for
271
+ # from an empty string. (Note that empty files can't be mapped, so the buffer
272
+ # created with ::map will never be empty.)
275
273
  #
276
274
  def empty?: () -> bool
277
275
 
278
276
  # <!--
279
277
  # rdoc-file=io_buffer.c
280
- # - external?()
278
+ # - external? -> true or false
281
279
  # -->
280
+ # The buffer is *external* if it references the memory which is not allocated or
281
+ # mapped by the buffer itself.
282
+ #
283
+ # A buffer created using ::for has an external reference to the string's memory.
284
+ #
285
+ # External buffer can't be resized.
282
286
  #
283
287
  def external?: () -> bool
284
288
 
@@ -294,6 +298,10 @@ class IO
294
298
  #
295
299
  # After the buffer is freed, no further operations can't be performed on it.
296
300
  #
301
+ # You can resize a freed buffer to re-allocate it.
302
+ #
303
+ # Example:
304
+ #
297
305
  # buffer = IO::Buffer.for('test')
298
306
  # buffer.free
299
307
  # # => #<IO::Buffer 0x0000000000000000+0 NULL>
@@ -307,8 +315,6 @@ class IO
307
315
  # buffer.null?
308
316
  # # => true
309
317
  #
310
- # You can resize a freed buffer to re-allocate it.
311
- #
312
318
  def free: () -> self
313
319
 
314
320
  # <!--
@@ -330,9 +336,9 @@ class IO
330
336
 
331
337
  # <!--
332
338
  # rdoc-file=io_buffer.c
333
- # - get_value(type, offset) -> numeric
339
+ # - get_value(data_type, offset) -> numeric
334
340
  # -->
335
- # Read from buffer a value of `type` at `offset`. `type` should be one of
341
+ # Read from buffer a value of `type` at `offset`. `data_type` should be one of
336
342
  # symbols:
337
343
  #
338
344
  # * `:U8`: unsigned integer, 1 byte
@@ -355,6 +361,10 @@ class IO
355
361
  # * `:F64`: double, 8 bytes, big-endian
356
362
  #
357
363
  #
364
+ # A data type refers specifically to the type of binary data that is stored in
365
+ # the buffer. For example, a `:u32` data type is a 32-bit unsigned integer in
366
+ # little-endian format.
367
+ #
358
368
  # Example:
359
369
  #
360
370
  # string = [1.5].pack('f')
@@ -413,6 +423,14 @@ class IO
413
423
  # block is performed, the buffer is considered locked, and no other code can
414
424
  # enter the lock. Also, locked buffer can't be changed with #resize or #free.
415
425
  #
426
+ # The following operations acquire a lock: #resize, #free.
427
+ #
428
+ # Locking is not thread safe. It is designed as a safety net around non-blocking
429
+ # system calls. You can only share a buffer between threads with appropriate
430
+ # synchronisation techniques.
431
+ #
432
+ # Example:
433
+ #
416
434
  # buffer = IO::Buffer.new(4)
417
435
  # buffer.locked? #=> false
418
436
  #
@@ -425,16 +443,10 @@ class IO
425
443
  # Fiber.schedule do
426
444
  # # in `locked': Buffer already locked! (IO::Buffer::LockedError)
427
445
  # buffer.locked do
428
- # buffer.set_string(...)
446
+ # buffer.set_string("test", 0)
429
447
  # end
430
448
  # end
431
449
  #
432
- # The following operations acquire a lock: #resize, #free.
433
- #
434
- # Locking is not thread safe. It is designed as a safety net around non-blocking
435
- # system calls. You can only share a buffer between threads with appropriate
436
- # synchronisation techniques.
437
- #
438
450
  def locked: [A] () { (IO::Buffer) -> A } -> A
439
451
 
440
452
  # <!--
@@ -448,6 +460,8 @@ class IO
448
460
  # Locking is not thread safe, but is a semantic used to ensure buffers don't
449
461
  # move while being used by a system call.
450
462
  #
463
+ # Example:
464
+ #
451
465
  # buffer.locked do
452
466
  # buffer.write(io) # theoretical system call interface
453
467
  # end
@@ -479,29 +493,89 @@ class IO
479
493
 
480
494
  # <!--
481
495
  # rdoc-file=io_buffer.c
482
- # - pread(p1, p2, p3)
496
+ # - pread(io, from, length, [offset]) -> read length or -errno
483
497
  # -->
498
+ # Read at most `length` bytes from `io` into the buffer, starting at `from`, and
499
+ # put it in buffer starting from specified `offset`. If an error occurs, return
500
+ # `-errno`.
501
+ #
502
+ # If `offset` is not given, put it at the beginning of the buffer.
503
+ #
504
+ # Example:
505
+ #
506
+ # IO::Buffer.for('test') do |buffer|
507
+ # p buffer
508
+ # # =>
509
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
510
+ # # 0x00000000 74 65 73 74 test
511
+ #
512
+ # # take 2 bytes from the beginning of urandom,
513
+ # # put them in buffer starting from position 2
514
+ # buffer.pread(File.open('/dev/urandom', 'rb'), 0, 2, 2)
515
+ # p buffer
516
+ # # =>
517
+ # # <IO::Buffer 0x00007f3bc65f2a58+4 EXTERNAL SLICE>
518
+ # # 0x00000000 05 35 73 74 te.5
519
+ # end
484
520
  #
485
521
  def pread: (untyped, untyped, untyped) -> untyped
486
522
 
487
523
  # <!--
488
524
  # rdoc-file=io_buffer.c
489
- # - pwrite(p1, p2, p3)
525
+ # - pwrite(io, from, length, [offset]) -> written length or -errno
490
526
  # -->
527
+ # Writes `length` bytes from buffer into `io`, starting at `offset` in the
528
+ # buffer. If an error occurs, return `-errno`.
529
+ #
530
+ # If `offset` is not given, the bytes are taken from the beginning of the
531
+ # buffer. If the `offset` is given and is beyond the end of the file, the gap
532
+ # will be filled with null (0 value) bytes.
533
+ #
534
+ # out = File.open('output.txt', File::RDWR) # open for read/write, no truncation
535
+ # IO::Buffer.for('1234567').pwrite(out, 2, 3, 1)
536
+ #
537
+ # This leads to `234` (3 bytes, starting from position 1) being written into
538
+ # `output.txt`, starting from file position 2.
491
539
  #
492
540
  def pwrite: (untyped, untyped, untyped) -> untyped
493
541
 
494
542
  # <!--
495
543
  # rdoc-file=io_buffer.c
496
- # - read(p1, p2)
544
+ # - read(io, [length, [offset]]) -> read length or -errno
497
545
  # -->
546
+ # Read at most `length` bytes from `io` into the buffer, starting at `offset`.
547
+ # If an error occurs, return `-errno`.
548
+ #
549
+ # If `length` is not given, read until the end of the buffer.
550
+ #
551
+ # If `offset` is not given, read from the beginning of the buffer.
552
+ #
553
+ # If `length` is 0, read nothing.
554
+ #
555
+ # Example:
556
+ #
557
+ # IO::Buffer.for('test') do |buffer|
558
+ # p buffer
559
+ # # =>
560
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
561
+ # # 0x00000000 74 65 73 74 test
562
+ # buffer.read(File.open('/dev/urandom', 'rb'), 2)
563
+ # p buffer
564
+ # # =>
565
+ # # <IO::Buffer 0x00007f3bc65f2a58+4 EXTERNAL SLICE>
566
+ # # 0x00000000 05 35 73 74 .5st
567
+ # end
498
568
  #
499
569
  def read: (untyped, untyped) -> untyped
500
570
 
501
571
  # <!--
502
572
  # rdoc-file=io_buffer.c
503
- # - readonly?()
573
+ # - readonly? -> true or false
504
574
  # -->
575
+ # If the buffer is *read only*, meaning the buffer cannot be modified using
576
+ # #set_value, #set_string or #copy and similar.
577
+ #
578
+ # Frozen strings and read-only files create read-only buffers.
505
579
  #
506
580
  def readonly?: () -> bool
507
581
 
@@ -516,7 +590,7 @@ class IO
516
590
  # buffer = IO::Buffer.new(4)
517
591
  # buffer.set_string("test", 0)
518
592
  # buffer.resize(8) # resize to 8 bytes
519
- # # =>
593
+ # # =>
520
594
  # # #<IO::Buffer 0x0000555f5d1a1630+8 INTERNAL>
521
595
  # # 0x00000000 74 65 73 74 00 00 00 00 test....
522
596
  #
@@ -526,8 +600,27 @@ class IO
526
600
 
527
601
  # <!--
528
602
  # rdoc-file=io_buffer.c
529
- # - set_string(*args)
603
+ # - set_string(string, [offset, [length, [source_offset]]]) -> size
530
604
  # -->
605
+ # Efficiently copy data from a source String into the buffer, at `offset` using
606
+ # `memcpy`.
607
+ #
608
+ # buf = IO::Buffer.new(8)
609
+ # # =>
610
+ # # #<IO::Buffer 0x0000557412714a20+8 INTERNAL>
611
+ # # 0x00000000 00 00 00 00 00 00 00 00 ........
612
+ #
613
+ # # set data starting from offset 1, take 2 bytes starting from string's
614
+ # # second
615
+ # buf.set_string('test', 1, 2, 1)
616
+ # # => 2
617
+ # buf
618
+ # # =>
619
+ # # #<IO::Buffer 0x0000557412714a20+8 INTERNAL>
620
+ # # 0x00000000 00 65 73 00 00 00 00 00 .es.....
621
+ #
622
+ # See also #copy for examples of how buffer writing might be used for changing
623
+ # associated strings and files.
531
624
  #
532
625
  def set_string: (*untyped) -> untyped
533
626
 
@@ -539,13 +632,15 @@ class IO
539
632
  # symbols described in #get_value.
540
633
  #
541
634
  # buffer = IO::Buffer.new(8)
542
- # # =>
635
+ # # =>
543
636
  # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
544
637
  # # 0x00000000 00 00 00 00 00 00 00 00
638
+ #
545
639
  # buffer.set_value(:U8, 1, 111)
546
640
  # # => 1
641
+ #
547
642
  # buffer
548
- # # =>
643
+ # # =>
549
644
  # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
550
645
  # # 0x00000000 00 6f 00 00 00 00 00 00 .o......
551
646
  #
@@ -554,11 +649,12 @@ class IO
554
649
  #
555
650
  # buffer = IO::Buffer.new(8)
556
651
  # buffer.set_value(:U32, 0, 2.5)
652
+ #
557
653
  # buffer
558
- # # =>
559
- # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
560
- # # 0x00000000 00 00 00 02 00 00 00 00
561
- # # ^^ the same as if we'd pass just integer 2
654
+ # # =>
655
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
656
+ # # 0x00000000 00 00 00 02 00 00 00 00
657
+ # # ^^ the same as if we'd pass just integer 2
562
658
  #
563
659
  def set_value: (int_get_type | float_get_type, Integer offset, Float | Integer value) -> Integer
564
660
 
@@ -573,7 +669,7 @@ class IO
573
669
 
574
670
  # <!--
575
671
  # rdoc-file=io_buffer.c
576
- # - slice(offset, length) -> io_buffer
672
+ # - slice([offset = 0, [length]]) -> io_buffer
577
673
  # -->
578
674
  # Produce another IO::Buffer which is a slice (or view into) the current one
579
675
  # starting at `offset` bytes and going for `length` bytes.
@@ -581,29 +677,48 @@ class IO
581
677
  # The slicing happens without copying of memory, and the slice keeps being
582
678
  # associated with the original buffer's source (string, or file), if any.
583
679
  #
584
- # Raises RuntimeError if the <tt>offset+length<tt> is out of the current
585
- # buffer's bounds.
680
+ # If the offset is not given, it will be zero. If the offset is negative, it
681
+ # will raise an ArgumentError.
682
+ #
683
+ # If the length is not given, the slice will be as long as the original buffer
684
+ # minus the specified offset. If the length is negative, it will raise an
685
+ # ArgumentError.
686
+ #
687
+ # Raises RuntimeError if the `offset+length` is out of the current buffer's
688
+ # bounds.
689
+ #
690
+ # Example:
586
691
  #
587
692
  # string = 'test'
588
693
  # buffer = IO::Buffer.for(string)
589
694
  #
695
+ # slice = buffer.slice
696
+ # # =>
697
+ # # #<IO::Buffer 0x0000000108338e68+4 SLICE>
698
+ # # 0x00000000 74 65 73 74 test
699
+ #
700
+ # buffer.slice(2)
701
+ # # =>
702
+ # # #<IO::Buffer 0x0000000108338e6a+2 SLICE>
703
+ # # 0x00000000 73 74 st
704
+ #
590
705
  # slice = buffer.slice(1, 2)
591
706
  # # =>
592
- # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
593
- # # 0x00000000 65 73 es
707
+ # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
708
+ # # 0x00000000 65 73 es
594
709
  #
595
710
  # # Put "o" into 0s position of the slice
596
711
  # slice.set_string('o', 0)
597
712
  # slice
598
713
  # # =>
599
- # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
600
- # # 0x00000000 6f 73 os
714
+ # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
715
+ # # 0x00000000 6f 73 os
601
716
  #
602
717
  # # it is also visible at position 1 of the original buffer
603
718
  # buffer
604
719
  # # =>
605
- # # #<IO::Buffer 0x00007fc3d31e2d80+4 SLICE>
606
- # # 0x00000000 74 6f 73 74 tost
720
+ # # #<IO::Buffer 0x00007fc3d31e2d80+4 SLICE>
721
+ # # 0x00000000 74 6f 73 74 tost
607
722
  #
608
723
  # # ...and original string
609
724
  # string
@@ -629,14 +744,16 @@ class IO
629
744
  # -->
630
745
  # Transfers ownership to a new buffer, deallocating the current one.
631
746
  #
747
+ # Example:
748
+ #
632
749
  # buffer = IO::Buffer.new('test')
633
750
  # other = buffer.transfer
634
751
  # other
635
- # # =>
752
+ # # =>
636
753
  # # #<IO::Buffer 0x00007f136a15f7b0+4 SLICE>
637
754
  # # 0x00000000 74 65 73 74 test
638
755
  # buffer
639
- # # =>
756
+ # # =>
640
757
  # # #<IO::Buffer 0x0000000000000000+0 NULL>
641
758
  # buffer.null?
642
759
  # # => true
@@ -656,8 +773,18 @@ class IO
656
773
 
657
774
  # <!--
658
775
  # rdoc-file=io_buffer.c
659
- # - write(p1, p2)
776
+ # - write(io, length, [offset]) -> written length or -errno
660
777
  # -->
778
+ # Writes `length` bytes from buffer into `io`, starting at `offset` in the
779
+ # buffer. If an error occurs, return `-errno`.
780
+ #
781
+ # If `offset` is not given, the bytes are taken from the beginning of the
782
+ # buffer.
783
+ #
784
+ # out = File.open('output.txt', 'wb')
785
+ # IO::Buffer.for('1234567').write(out, 3)
786
+ #
787
+ # This leads to `123` being written into `output.txt`
661
788
  #
662
789
  def write: (untyped, untyped) -> untyped
663
790
 
@@ -669,7 +796,7 @@ class IO
669
796
  # -->
670
797
  # Create a new zero-filled IO::Buffer of `size` bytes. By default, the buffer
671
798
  # will be *internal*: directly allocated chunk of the memory. But if the
672
- # requested `size` is more than OS-specific IO::Bufer::PAGE_SIZE, the buffer
799
+ # requested `size` is more than OS-specific IO::Buffer::PAGE_SIZE, the buffer
673
800
  # would be allocated using the virtual memory mechanism (anonymous `mmap` on
674
801
  # Unix, `VirtualAlloc` on Windows). The behavior can be forced by passing
675
802
  # IO::Buffer::MAPPED as a second parameter.
@@ -678,14 +805,14 @@ class IO
678
805
  #
679
806
  # buffer = IO::Buffer.new(4)
680
807
  # # =>
681
- # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
682
- # # 0x00000000 00 00 00 00 ....
808
+ # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
809
+ # # 0x00000000 00 00 00 00 ....
683
810
  #
684
811
  # buffer.get_string(0, 1) # => "\x00"
685
812
  #
686
813
  # buffer.set_string("test")
687
814
  # buffer
688
- # # =>
815
+ # # =>
689
816
  # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
690
817
  # # 0x00000000 74 65 73 74 test
691
818
  #
data/core/io/wait.rbs CHANGED
@@ -7,52 +7,64 @@ class IO
7
7
  # Returns number of bytes that can be read without blocking. Returns zero if no
8
8
  # information available.
9
9
  #
10
+ # You must require 'io/wait' to use this method.
11
+ #
10
12
  def nread: () -> Integer
11
13
 
12
14
  # <!--
13
15
  # rdoc-file=ext/io/wait/wait.c
14
- # - io.ready? -> true or false
16
+ # - io.ready? -> truthy or falsy
15
17
  # -->
16
- # Returns `true` if input available without blocking, or `false`.
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.
17
21
  #
18
22
  def ready?: () -> boolish
19
23
 
20
24
  # <!--
21
25
  # rdoc-file=ext/io/wait/wait.c
22
- # - io.wait(events, timeout) -> event mask or false.
23
- # - io.wait(timeout = nil, mode = :read) -> event mask or false.
26
+ # - io.wait(events, timeout) -> event mask, false or nil
27
+ # - io.wait(timeout = nil, mode = :read) -> self, true, or false
24
28
  # -->
25
29
  # Waits until the IO becomes ready for the specified events and returns the
26
- # subset of events that become ready, or `false` when times out.
30
+ # subset of events that become ready, or a falsy value when times out.
27
31
  #
28
32
  # The events can be a bit mask of `IO::READABLE`, `IO::WRITABLE` or
29
33
  # `IO::PRIORITY`.
30
34
  #
31
- # Returns `true` immediately when buffered data is available.
35
+ # Returns a truthy value immediately when buffered data is available.
32
36
  #
33
37
  # Optional parameter `mode` is one of `:read`, `:write`, or `:read_write`.
34
38
  #
35
- def wait: (Integer events, ?Numeric timeout) -> (self | bool | nil)
36
- | (?Numeric? timeout, *wait_mode mode) -> (self | bool | nil)
39
+ # You must require 'io/wait' to use this method.
40
+ #
41
+ def wait: (Integer events, ?Numeric timeout) -> (Integer | false | nil)
42
+ | (?Numeric? timeout, *wait_mode mode) -> (self | true | false)
37
43
 
38
44
  type wait_mode = :read | :r | :readable | :write | :w | :writable | :read_write | :rw | :readable_writable
39
45
 
40
46
  # <!--
41
47
  # rdoc-file=ext/io/wait/wait.c
42
- # - io.wait_readable -> true or false
43
- # - io.wait_readable(timeout) -> true or false
48
+ # - io.wait_readable -> truthy or falsy
49
+ # - io.wait_readable(timeout) -> truthy or falsy
44
50
  # -->
45
- # Waits until IO is readable and returns `true`, or `false` when times out.
46
- # Returns `true` immediately when buffered data is available.
51
+ # Waits until IO is readable and returns a truthy value, or a falsy value when
52
+ # times out. Returns a truthy value immediately when buffered data is
53
+ # available.
47
54
  #
48
- def wait_readable: (?Numeric? timeout) -> (self | bool | nil)?
55
+ # You must require 'io/wait' to use this method.
56
+ #
57
+ def wait_readable: (?Numeric? timeout) -> boolish
49
58
 
50
59
  # <!--
51
60
  # rdoc-file=ext/io/wait/wait.c
52
- # - io.wait_writable -> true or false
53
- # - io.wait_writable(timeout) -> true or false
61
+ # - io.wait_writable -> truthy or falsy
62
+ # - io.wait_writable(timeout) -> truthy or falsy
54
63
  # -->
55
- # Waits until IO is writable and returns `true` or `false` when times out.
64
+ # Waits until IO is writable and returns a truthy value or a falsy value when
65
+ # times out.
66
+ #
67
+ # You must require 'io/wait' to use this method.
56
68
  #
57
69
  def wait_writable: (?Numeric? timeout) -> boolish
58
70
  end