rbs 3.10.0.pre.2 → 3.10.0

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/c-check.yml +1 -1
  3. data/.github/workflows/comments.yml +2 -2
  4. data/.github/workflows/ruby.yml +7 -7
  5. data/CHANGELOG.md +49 -0
  6. data/core/array.rbs +56 -3
  7. data/core/complex.rbs +32 -21
  8. data/core/encoding.rbs +3 -7
  9. data/core/enumerable.rbs +1 -1
  10. data/core/enumerator.rbs +18 -1
  11. data/core/fiber.rbs +2 -1
  12. data/core/file.rbs +1 -1
  13. data/core/file_test.rbs +1 -1
  14. data/core/float.rbs +208 -21
  15. data/core/gc.rbs +4 -9
  16. data/core/hash.rbs +4 -4
  17. data/core/integer.rbs +78 -38
  18. data/core/io/buffer.rbs +18 -7
  19. data/core/io.rbs +8 -8
  20. data/core/kernel.rbs +8 -8
  21. data/core/module.rbs +17 -6
  22. data/core/numeric.rbs +8 -8
  23. data/core/object_space.rbs +13 -20
  24. data/core/pathname.rbs +2 -3
  25. data/core/ractor.rbs +4 -4
  26. data/core/range.rbs +1 -1
  27. data/core/rational.rbs +37 -24
  28. data/core/rbs/unnamed/argf.rbs +1 -1
  29. data/core/regexp.rbs +3 -3
  30. data/core/ruby.rbs +53 -0
  31. data/core/rubygems/version.rbs +2 -3
  32. data/core/set.rbs +86 -64
  33. data/core/string.rbs +275 -141
  34. data/core/thread.rbs +9 -9
  35. data/core/trace_point.rbs +7 -4
  36. data/lib/rbs/test/type_check.rb +1 -0
  37. data/lib/rbs/version.rb +1 -1
  38. data/lib/rdoc/discover.rb +1 -1
  39. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  40. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  41. data/stdlib/date/0/date.rbs +67 -59
  42. data/stdlib/date/0/date_time.rbs +1 -1
  43. data/stdlib/json/0/json.rbs +1 -0
  44. data/stdlib/objspace/0/objspace.rbs +1 -1
  45. data/stdlib/openssl/0/openssl.rbs +150 -80
  46. data/stdlib/psych/0/psych.rbs +3 -3
  47. data/stdlib/stringio/0/stringio.rbs +796 -37
  48. data/stdlib/strscan/0/string_scanner.rbs +1 -1
  49. data/stdlib/tempfile/0/tempfile.rbs +2 -2
  50. data/stdlib/time/0/time.rbs +1 -1
  51. data/stdlib/timeout/0/timeout.rbs +63 -7
  52. data/stdlib/uri/0/generic.rbs +1 -1
  53. metadata +3 -2
data/core/set.rbs CHANGED
@@ -1,16 +1,9 @@
1
1
  # <!-- rdoc-file=set.c -->
2
- # Copyright (c) 2002-2024 Akinori MUSHA <knu@iDaemons.org>
3
- #
4
- # Documentation by Akinori MUSHA and Gavin Sinclair.
5
- #
6
- # All rights reserved. You can redistribute and/or modify it under the same
7
- # terms as Ruby.
8
- #
9
2
  # The Set class implements a collection of unordered values with no duplicates.
10
3
  # It is a hybrid of Array's intuitive inter-operation facilities and Hash's fast
11
4
  # lookup.
12
5
  #
13
- # Set is easy to use with Enumerable objects (implementing `each`). Most of the
6
+ # Set is easy to use with Enumerable objects (implementing #each). Most of the
14
7
  # initializer methods and binary operators accept generic Enumerable objects
15
8
  # besides sets and arrays. An Enumerable object can be converted to Set using
16
9
  # the `to_set` method.
@@ -36,11 +29,11 @@
36
29
  #
37
30
  # ## Example
38
31
  #
39
- # s1 = Set[1, 2] #=> #<Set: {1, 2}>
40
- # s2 = [1, 2].to_set #=> #<Set: {1, 2}>
32
+ # s1 = Set[1, 2] #=> Set[1, 2]
33
+ # s2 = [1, 2].to_set #=> Set[1, 2]
41
34
  # s1 == s2 #=> true
42
- # s1.add("foo") #=> #<Set: {1, 2, "foo"}>
43
- # s1.merge([2, 6]) #=> #<Set: {1, 2, "foo", 6}>
35
+ # s1.add("foo") #=> Set[1, 2, "foo"]
36
+ # s1.merge([2, 6]) #=> Set[1, 2, "foo", 6]
44
37
  # s1.subset?(s2) #=> false
45
38
  # s2.subset?(s1) #=> true
46
39
  #
@@ -48,9 +41,39 @@
48
41
  #
49
42
  # * Akinori MUSHA <knu@iDaemons.org> (current maintainer)
50
43
  #
51
- # ## What's Here
44
+ # ## Inheriting from Set
45
+ #
46
+ # Before Ruby 4.0 (released December 2025), Set had a different, less efficient
47
+ # implementation. It was reimplemented in C, and the behavior of some of the
48
+ # core methods were adjusted.
49
+ #
50
+ # To keep backward compatibility, when a class is inherited from Set, additional
51
+ # module `Set::SubclassCompatible` is included, which makes the inherited class
52
+ # behavior, as well as internal method names, closer to what it was before Ruby
53
+ # 4.0.
54
+ #
55
+ # It can be easily seen, for example, in the #inspect method behavior:
56
+ #
57
+ # p Set[1, 2, 3]
58
+ # # prints "Set[1, 2, 3]"
59
+ #
60
+ # class MySet < Set
61
+ # end
62
+ # p MySet[1, 2, 3]
63
+ # # prints "#<MySet: {1, 2, 3}>", like it was in Ruby 3.4
64
+ #
65
+ # For new code, if backward compatibility is not necessary, it is recommended to
66
+ # instead inherit from `Set::CoreSet`, which avoids including the
67
+ # "compatibility" layer:
68
+ #
69
+ # class MyCoreSet < Set::CoreSet
70
+ # end
71
+ # p MyCoreSet[1, 2, 3]
72
+ # # prints "MyCoreSet[1, 2, 3]"
73
+ #
74
+ # ## Set's methods
52
75
  #
53
- # First, what's elsewhere. \Class \Set:
76
+ # First, what's elsewhere. Class Set:
54
77
  #
55
78
  # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
56
79
  # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
@@ -61,16 +84,15 @@
61
84
  #
62
85
  # Here, class Set provides methods that are useful for:
63
86
  #
64
- # * [Creating an Array](rdoc-ref:Array@Methods+for+Creating+an+Array)
65
87
  # * [Creating a Set](rdoc-ref:Set@Methods+for+Creating+a+Set)
66
88
  # * [Set Operations](rdoc-ref:Set@Methods+for+Set+Operations)
67
- # * [Comparing](rdoc-ref:Array@Methods+for+Comparing)
68
- # * [Querying](rdoc-ref:Array@Methods+for+Querying)
69
- # * [Assigning](rdoc-ref:Array@Methods+for+Assigning)
70
- # * [Deleting](rdoc-ref:Array@Methods+for+Deleting)
71
- # * [Converting](rdoc-ref:Array@Methods+for+Converting)
72
- # * [Iterating](rdoc-ref:Array@Methods+for+Iterating)
73
- # * [And more....](rdoc-ref:Array@Other+Methods)
89
+ # * [Comparing](rdoc-ref:Set@Methods+for+Comparing)
90
+ # * [Querying](rdoc-ref:Set@Methods+for+Querying)
91
+ # * [Assigning](rdoc-ref:Set@Methods+for+Assigning)
92
+ # * [Deleting](rdoc-ref:Set@Methods+for+Deleting)
93
+ # * [Converting](rdoc-ref:Set@Methods+for+Converting)
94
+ # * [Iterating](rdoc-ref:Set@Methods+for+Iterating)
95
+ # * [And more....](rdoc-ref:Set@Other+Methods)
74
96
  #
75
97
  # ### Methods for Creating a Set
76
98
  #
@@ -183,11 +205,11 @@ class Set[unchecked out A]
183
205
  #
184
206
  # If a block is given, the elements of enum are preprocessed by the given block.
185
207
  #
186
- # Set.new([1, 2]) #=> #<Set: {1, 2}>
187
- # Set.new([1, 2, 1]) #=> #<Set: {1, 2}>
188
- # Set.new([1, 'c', :s]) #=> #<Set: {1, "c", :s}>
189
- # Set.new(1..5) #=> #<Set: {1, 2, 3, 4, 5}>
190
- # Set.new([1, 2, 3]) { |x| x * x } #=> #<Set: {1, 4, 9}>
208
+ # Set.new([1, 2]) #=> Set[1, 2]
209
+ # Set.new([1, 2, 1]) #=> Set[1, 2]
210
+ # Set.new([1, 'c', :s]) #=> Set[1, "c", :s]
211
+ # Set.new(1..5) #=> Set[1, 2, 3, 4, 5]
212
+ # Set.new([1, 2, 3]) { |x| x * x } #=> Set[1, 4, 9]
191
213
  #
192
214
  def initialize: (_Each[A]) -> untyped
193
215
  | [X] (_Each[X]) { (X) -> A } -> untyped
@@ -208,8 +230,8 @@ class Set[unchecked out A]
208
230
  # Returns a new set containing elements common to the set and the given
209
231
  # enumerable object.
210
232
  #
211
- # Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
212
- # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
233
+ # Set[1, 3, 5] & Set[3, 2, 1] #=> Set[3, 1]
234
+ # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> Set["a", "b"]
213
235
  #
214
236
  def &: (_Each[A]) -> self
215
237
 
@@ -217,8 +239,8 @@ class Set[unchecked out A]
217
239
  # Returns a new set containing elements common to the set and the given
218
240
  # enumerable object.
219
241
  #
220
- # Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
221
- # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
242
+ # Set[1, 3, 5] & Set[3, 2, 1] #=> Set[3, 1]
243
+ # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> Set["a", "b"]
222
244
  #
223
245
  alias intersection &
224
246
 
@@ -229,8 +251,8 @@ class Set[unchecked out A]
229
251
  # Returns a new set built by merging the set and the elements of the given
230
252
  # enumerable object.
231
253
  #
232
- # Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
233
- # Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
254
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> Set[1, 2, 3, 4, 5]
255
+ # Set[1, 5, 'z'] | (1..6) #=> Set[1, 5, "z", 2, 3, 4, 6]
234
256
  #
235
257
  def |: (_Each[A]) -> self
236
258
 
@@ -238,8 +260,8 @@ class Set[unchecked out A]
238
260
  # Returns a new set built by merging the set and the elements of the given
239
261
  # enumerable object.
240
262
  #
241
- # Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
242
- # Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
263
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> Set[1, 2, 3, 4, 5]
264
+ # Set[1, 5, 'z'] | (1..6) #=> Set[1, 5, "z", 2, 3, 4, 6]
243
265
  #
244
266
  alias union |
245
267
 
@@ -247,8 +269,8 @@ class Set[unchecked out A]
247
269
  # Returns a new set built by merging the set and the elements of the given
248
270
  # enumerable object.
249
271
  #
250
- # Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
251
- # Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
272
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> Set[1, 2, 3, 4, 5]
273
+ # Set[1, 5, 'z'] | (1..6) #=> Set[1, 5, "z", 2, 3, 4, 6]
252
274
  #
253
275
  alias + |
254
276
 
@@ -259,8 +281,8 @@ class Set[unchecked out A]
259
281
  # Returns a new set built by duplicating the set, removing every element that
260
282
  # appears in the given enumerable object.
261
283
  #
262
- # Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
263
- # Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
284
+ # Set[1, 3, 5] - Set[1, 5] #=> Set[3]
285
+ # Set['a', 'b', 'z'] - ['a', 'c'] #=> Set["b", "z"]
264
286
  #
265
287
  def -: (_Each[A]) -> self
266
288
 
@@ -268,8 +290,8 @@ class Set[unchecked out A]
268
290
  # Returns a new set built by duplicating the set, removing every element that
269
291
  # appears in the given enumerable object.
270
292
  #
271
- # Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
272
- # Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
293
+ # Set[1, 3, 5] - Set[1, 5] #=> Set[3]
294
+ # Set['a', 'b', 'z'] - ['a', 'c'] #=> Set["b", "z"]
273
295
  #
274
296
  alias difference -
275
297
 
@@ -280,9 +302,9 @@ class Set[unchecked out A]
280
302
  # Adds the given object to the set and returns self. Use `merge` to add many
281
303
  # elements at once.
282
304
  #
283
- # Set[1, 2].add(3) #=> #<Set: {1, 2, 3}>
284
- # Set[1, 2].add([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
285
- # Set[1, 2].add(2) #=> #<Set: {1, 2}>
305
+ # Set[1, 2].add(3) #=> Set[1, 2, 3]
306
+ # Set[1, 2].add([3, 4]) #=> Set[1, 2, [3, 4]]
307
+ # Set[1, 2].add(2) #=> Set[1, 2]
286
308
  #
287
309
  def add: (A) -> self
288
310
 
@@ -290,9 +312,9 @@ class Set[unchecked out A]
290
312
  # Adds the given object to the set and returns self. Use `merge` to add many
291
313
  # elements at once.
292
314
  #
293
- # Set[1, 2].add(3) #=> #<Set: {1, 2, 3}>
294
- # Set[1, 2].add([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
295
- # Set[1, 2].add(2) #=> #<Set: {1, 2}>
315
+ # Set[1, 2].add(3) #=> Set[1, 2, 3]
316
+ # Set[1, 2].add([3, 4]) #=> Set[1, 2, [3, 4]]
317
+ # Set[1, 2].add(2) #=> Set[1, 2]
296
318
  #
297
319
  alias << add
298
320
 
@@ -303,8 +325,8 @@ class Set[unchecked out A]
303
325
  # Adds the given object to the set and returns self. If the object is already in
304
326
  # the set, returns nil.
305
327
  #
306
- # Set[1, 2].add?(3) #=> #<Set: {1, 2, 3}>
307
- # Set[1, 2].add?([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
328
+ # Set[1, 2].add?(3) #=> Set[1, 2, 3]
329
+ # Set[1, 2].add?([3, 4]) #=> Set[1, 2, [3, 4]]
308
330
  # Set[1, 2].add?(2) #=> nil
309
331
  #
310
332
  def add?: (A) -> self?
@@ -366,8 +388,8 @@ class Set[unchecked out A]
366
388
  # enumerable object. `(set ^ enum)` is equivalent to `((set | enum) - (set &
367
389
  # enum))`.
368
390
  #
369
- # Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
370
- # Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
391
+ # Set[1, 2] ^ Set[2, 3] #=> Set[3, 1]
392
+ # Set[1, 'b', 'c'] ^ ['b', 'd'] #=> Set["d", 1, "c"]
371
393
  #
372
394
  def ^: (_Each[A]) -> self
373
395
 
@@ -382,9 +404,9 @@ class Set[unchecked out A]
382
404
  #
383
405
  # files = Set.new(Dir.glob("*.rb"))
384
406
  # hash = files.classify { |f| File.mtime(f).year }
385
- # hash #=> {2000 => #<Set: {"a.rb", "b.rb"}>,
386
- # # 2001 => #<Set: {"c.rb", "d.rb", "e.rb"}>,
387
- # # 2002 => #<Set: {"f.rb"}>}
407
+ # hash #=> {2000 => Set["a.rb", "b.rb"],
408
+ # # 2001 => Set["c.rb", "d.rb", "e.rb"],
409
+ # # 2002 => Set["f.rb"]}
388
410
  #
389
411
  # Returns an enumerator if no block is given.
390
412
  #
@@ -396,9 +418,9 @@ class Set[unchecked out A]
396
418
  # -->
397
419
  # Removes all elements and returns self.
398
420
  #
399
- # set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
400
- # set.clear #=> #<Set: {}>
401
- # set #=> #<Set: {}>
421
+ # set = Set[1, 'c', :s] #=> Set[1, "c", :s]
422
+ # set.clear #=> Set[]
423
+ # set #=> Set[]
402
424
  #
403
425
  def clear: () -> self
404
426
 
@@ -502,10 +524,10 @@ class Set[unchecked out A]
502
524
  #
503
525
  # numbers = Set[1, 3, 4, 6, 9, 10, 11]
504
526
  # set = numbers.divide { |i,j| (i - j).abs == 1 }
505
- # set #=> #<Set: {#<Set: {1}>,
506
- # # #<Set: {3, 4}>,
507
- # # #<Set: {6}>}>
508
- # # #<Set: {9, 10, 11}>,
527
+ # set #=> Set[Set[1],
528
+ # # Set[3, 4],
529
+ # # Set[6],
530
+ # # Set[9, 10, 11]]
509
531
  #
510
532
  # Returns an enumerator if no block is given.
511
533
  #
@@ -654,9 +676,9 @@ class Set[unchecked out A]
654
676
  # Replaces the contents of the set with the contents of the given enumerable
655
677
  # object and returns self.
656
678
  #
657
- # set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
658
- # set.replace([1, 2]) #=> #<Set: {1, 2}>
659
- # set #=> #<Set: {1, 2}>
679
+ # set = Set[1, 'c', :s] #=> Set[1, "c", :s]
680
+ # set.replace([1, 2]) #=> Set[1, 2]
681
+ # set #=> Set[1, 2]
660
682
  #
661
683
  def replace: (_Each[A]) -> self
662
684