rbs 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +7 -2
  5. data/Gemfile +3 -0
  6. data/README.md +8 -2
  7. data/Steepfile +1 -0
  8. data/bin/annotate-with-rdoc +1 -1
  9. data/bin/setup +0 -2
  10. data/docs/CONTRIBUTING.md +1 -0
  11. data/goodcheck.yml +22 -5
  12. data/lib/rbs/ast/comment.rb +1 -1
  13. data/lib/rbs/definition_builder.rb +4 -5
  14. data/lib/rbs/environment.rb +1 -1
  15. data/lib/rbs/namespace.rb +1 -1
  16. data/lib/rbs/parser.rb +3146 -0
  17. data/lib/rbs/parser.y +7 -2
  18. data/lib/rbs/test/setup_helper.rb +4 -4
  19. data/lib/rbs/test/type_check.rb +2 -2
  20. data/lib/rbs/type_name.rb +1 -1
  21. data/lib/rbs/variance_calculator.rb +1 -1
  22. data/lib/rbs/version.rb +1 -1
  23. data/lib/rbs/writer.rb +1 -1
  24. data/sig/constant.rbs +2 -2
  25. data/sig/constant_table.rbs +10 -10
  26. data/sig/declarations.rbs +1 -1
  27. data/sig/definition.rbs +1 -1
  28. data/sig/namespace.rbs +3 -3
  29. data/sig/parser.rbs +25 -0
  30. data/sig/substitution.rbs +3 -3
  31. data/sig/typename.rbs +1 -1
  32. data/sig/types.rbs +1 -1
  33. data/sig/writer.rbs +15 -15
  34. data/stdlib/benchmark/benchmark.rbs +2 -2
  35. data/stdlib/builtin/basic_object.rbs +54 -54
  36. data/stdlib/builtin/binding.rbs +42 -42
  37. data/stdlib/builtin/class.rbs +33 -33
  38. data/stdlib/builtin/complex.rbs +90 -90
  39. data/stdlib/builtin/encoding.rbs +33 -33
  40. data/stdlib/builtin/enumerable.rbs +32 -32
  41. data/stdlib/builtin/enumerator.rbs +35 -35
  42. data/stdlib/builtin/errors.rbs +1 -1
  43. data/stdlib/builtin/exception.rbs +50 -50
  44. data/stdlib/builtin/false_class.rbs +6 -6
  45. data/stdlib/builtin/fiber.rbs +14 -14
  46. data/stdlib/builtin/fiber_error.rbs +1 -1
  47. data/stdlib/builtin/float.rbs +161 -161
  48. data/stdlib/builtin/gc.rbs +1 -1
  49. data/stdlib/builtin/io.rbs +83 -83
  50. data/stdlib/builtin/kernel.rbs +69 -69
  51. data/stdlib/builtin/match_data.rbs +1 -1
  52. data/stdlib/builtin/method.rbs +19 -19
  53. data/stdlib/builtin/nil_class.rbs +20 -20
  54. data/stdlib/builtin/numeric.rbs +101 -101
  55. data/stdlib/builtin/object.rbs +172 -172
  56. data/stdlib/builtin/proc.rbs +91 -91
  57. data/stdlib/builtin/range.rbs +2 -4
  58. data/stdlib/builtin/rational.rbs +83 -83
  59. data/stdlib/builtin/signal.rbs +7 -7
  60. data/stdlib/builtin/string.rbs +4 -4
  61. data/stdlib/builtin/string_io.rbs +1 -1
  62. data/stdlib/builtin/thread.rbs +185 -185
  63. data/stdlib/builtin/thread_group.rbs +2 -2
  64. data/stdlib/builtin/true_class.rbs +9 -9
  65. data/stdlib/builtin/warning.rbs +1 -1
  66. data/stdlib/date/date.rbs +2 -2
  67. data/stdlib/find/find.rbs +10 -10
  68. data/stdlib/pathname/pathname.rbs +1 -1
  69. data/stdlib/tmpdir/tmpdir.rbs +12 -12
  70. metadata +3 -2
@@ -87,11 +87,9 @@
87
87
  # r.to_a #=> [xxx, xxxx, xxxxx, xxxxxx]
88
88
  # r.member?(Xs.new(5)) #=> true
89
89
  # ```
90
- class Range[Elem] < Object
90
+ class Range[out Elem] < Object
91
91
  include Enumerable[Elem, Range[Elem]]
92
92
 
93
- def self.new: [U] (U from, U to, ?bool exclude_end) -> ::Range[U]
94
-
95
93
  def ==: (untyped obj) -> bool
96
94
 
97
95
  def ===: (untyped obj) -> bool
@@ -146,7 +144,7 @@ class Range[Elem] < Object
146
144
 
147
145
  def `include?`: (untyped obj) -> bool
148
146
 
149
- def initialize: (Elem _begin, Elem _end, ?bool exclude_end) -> void
147
+ def initialize: (Elem from, Elem to, ?bool exclude_end) -> void
150
148
 
151
149
  # Convert this range object to a printable form (using `inspect` to
152
150
  # convert the begin and end objects).
@@ -1,43 +1,43 @@
1
1
  # A rational number can be represented as a pair of integer numbers: a/b (b>0),
2
2
  # where a is the numerator and b is the denominator. Integer a equals rational
3
3
  # a/1 mathematically.
4
- #
4
+ #
5
5
  # In Ruby, you can create rational objects with the Kernel#Rational, to_r, or
6
6
  # rationalize methods or by suffixing `r` to a literal. The return values will
7
7
  # be irreducible fractions.
8
- #
8
+ #
9
9
  # Rational(1) #=> (1/1)
10
10
  # Rational(2, 3) #=> (2/3)
11
11
  # Rational(4, -6) #=> (-2/3)
12
12
  # 3.to_r #=> (3/1)
13
13
  # 2/3r #=> (2/3)
14
- #
14
+ #
15
15
  # You can also create rational objects from floating-point numbers or strings.
16
- #
16
+ #
17
17
  # Rational(0.3) #=> (5404319552844595/18014398509481984)
18
18
  # Rational('0.3') #=> (3/10)
19
19
  # Rational('2/3') #=> (2/3)
20
- #
20
+ #
21
21
  # 0.3.to_r #=> (5404319552844595/18014398509481984)
22
22
  # '0.3'.to_r #=> (3/10)
23
23
  # '2/3'.to_r #=> (2/3)
24
24
  # 0.3.rationalize #=> (3/10)
25
- #
25
+ #
26
26
  # A rational object is an exact number, which helps you to write programs
27
27
  # without any rounding errors.
28
- #
28
+ #
29
29
  # 10.times.inject(0) {|t| t + 0.1 } #=> 0.9999999999999999
30
30
  # 10.times.inject(0) {|t| t + Rational('0.1') } #=> (1/1)
31
- #
31
+ #
32
32
  # However, when an expression includes an inexact component (numerical value or
33
33
  # operation), it will produce an inexact result.
34
- #
34
+ #
35
35
  # Rational(10) / 3 #=> (10/3)
36
36
  # Rational(10) / 3.0 #=> 3.3333333333333335
37
- #
37
+ #
38
38
  # Rational(-8) ** Rational(1, 3)
39
39
  # #=> (1.0000000000000002+1.7320508075688772i)
40
- #
40
+ #
41
41
  class Rational < Numeric
42
42
  public
43
43
 
@@ -47,37 +47,37 @@ class Rational < Numeric
47
47
  | (Numeric) -> Numeric
48
48
 
49
49
  # Performs multiplication.
50
- #
50
+ #
51
51
  # Rational(2, 3) * Rational(2, 3) #=> (4/9)
52
52
  # Rational(900) * Rational(1) #=> (900/1)
53
53
  # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
54
54
  # Rational(9, 8) * 4 #=> (9/2)
55
55
  # Rational(20, 9) * 9.8 #=> 21.77777777777778
56
- #
56
+ #
57
57
  def *: (Float) -> Float
58
58
  | (Complex) -> Complex
59
59
  | (Numeric) -> Numeric
60
60
 
61
61
  # Performs exponentiation.
62
- #
62
+ #
63
63
  # Rational(2) ** Rational(3) #=> (8/1)
64
64
  # Rational(10) ** -2 #=> (1/100)
65
65
  # Rational(10) ** -2.0 #=> 0.01
66
66
  # Rational(-4) ** Rational(1, 2) #=> (0.0+2.0i)
67
67
  # Rational(1, 2) ** 0 #=> (1/1)
68
68
  # Rational(1, 2) ** 0.0 #=> 1.0
69
- #
69
+ #
70
70
  def **: (Complex) -> Complex
71
71
  | (Numeric) -> Numeric
72
72
 
73
73
  # Performs addition.
74
- #
74
+ #
75
75
  # Rational(2, 3) + Rational(2, 3) #=> (4/3)
76
76
  # Rational(900) + Rational(1) #=> (901/1)
77
77
  # Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
78
78
  # Rational(9, 8) + 4 #=> (41/8)
79
79
  # Rational(20, 9) + 9.8 #=> 12.022222222222222
80
- #
80
+ #
81
81
  def +: (Float) -> Float
82
82
  | (Complex) -> Complex
83
83
  | (Numeric) -> Rational
@@ -85,65 +85,65 @@ class Rational < Numeric
85
85
  def +@: () -> Rational
86
86
 
87
87
  # Performs subtraction.
88
- #
88
+ #
89
89
  # Rational(2, 3) - Rational(2, 3) #=> (0/1)
90
90
  # Rational(900) - Rational(1) #=> (899/1)
91
91
  # Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
92
92
  # Rational(9, 8) - 4 #=> (-23/8)
93
93
  # Rational(20, 9) - 9.8 #=> -7.577777777777778
94
- #
94
+ #
95
95
  def -: (Float) -> Float
96
96
  | (Complex) -> Complex
97
97
  | (Numeric) -> Rational
98
98
 
99
99
  # Negates `rat`.
100
- #
100
+ #
101
101
  def -@: () -> Rational
102
102
 
103
103
  # Performs division.
104
- #
104
+ #
105
105
  # Rational(2, 3) / Rational(2, 3) #=> (1/1)
106
106
  # Rational(900) / Rational(1) #=> (900/1)
107
107
  # Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
108
108
  # Rational(9, 8) / 4 #=> (9/32)
109
109
  # Rational(20, 9) / 9.8 #=> 0.22675736961451246
110
- #
110
+ #
111
111
  def /: (Float) -> Float
112
112
  | (Complex) -> Complex
113
113
  | (Numeric) -> Rational
114
114
 
115
115
  # Returns -1, 0, or +1 depending on whether `rational` is less than, equal to,
116
116
  # or greater than `numeric`.
117
- #
117
+ #
118
118
  # `nil` is returned if the two values are incomparable.
119
- #
119
+ #
120
120
  # Rational(2, 3) <=> Rational(2, 3) #=> 0
121
121
  # Rational(5) <=> 5 #=> 0
122
122
  # Rational(2, 3) <=> Rational(1, 3) #=> 1
123
123
  # Rational(1, 3) <=> 1 #=> -1
124
124
  # Rational(1, 3) <=> 0.3 #=> 1
125
- #
125
+ #
126
126
  # Rational(1, 3) <=> "0.3" #=> nil
127
- #
127
+ #
128
128
  def <=>: (Numeric) -> Integer?
129
129
 
130
130
  # Returns `true` if `rat` equals `object` numerically.
131
- #
131
+ #
132
132
  # Rational(2, 3) == Rational(2, 3) #=> true
133
133
  # Rational(5) == 5 #=> true
134
134
  # Rational(0) == 0.0 #=> true
135
135
  # Rational('1/3') == 0.33 #=> false
136
136
  # Rational('1/2') == '1/2' #=> false
137
- #
137
+ #
138
138
  def ==: (untyped) -> bool
139
139
 
140
140
  # Returns the absolute value of `rat`.
141
- #
141
+ #
142
142
  # (1/2r).abs #=> (1/2)
143
143
  # (-1/2r).abs #=> (1/2)
144
- #
144
+ #
145
145
  # Rational#magnitude is an alias for Rational#abs.
146
- #
146
+ #
147
147
  def abs: () -> Rational
148
148
 
149
149
  def abs2: () -> Rational
@@ -154,23 +154,23 @@ class Rational < Numeric
154
154
 
155
155
  # Returns the smallest number greater than or equal to `rat` with a precision of
156
156
  # `ndigits` decimal digits (default: 0).
157
- #
157
+ #
158
158
  # When the precision is negative, the returned value is an integer with at least
159
159
  # `ndigits.abs` trailing zeros.
160
- #
160
+ #
161
161
  # Returns a rational when `ndigits` is positive, otherwise returns an integer.
162
- #
162
+ #
163
163
  # Rational(3).ceil #=> 3
164
164
  # Rational(2, 3).ceil #=> 1
165
165
  # Rational(-3, 2).ceil #=> -1
166
- #
166
+ #
167
167
  # # decimal - 1 2 3 . 4 5 6
168
168
  # # ^ ^ ^ ^ ^ ^
169
169
  # # precision -3 -2 -1 0 +1 +2
170
- #
170
+ #
171
171
  # Rational('-123.456').ceil(+1).to_f #=> -123.4
172
172
  # Rational('-123.456').ceil(-1) #=> -120
173
- #
173
+ #
174
174
  def ceil: () -> Integer
175
175
  | (Integer digits) -> (Integer | Rational)
176
176
 
@@ -183,12 +183,12 @@ class Rational < Numeric
183
183
  def conjugate: () -> Rational
184
184
 
185
185
  # Returns the denominator (always positive).
186
- #
186
+ #
187
187
  # Rational(7).denominator #=> 1
188
188
  # Rational(7, 1).denominator #=> 1
189
189
  # Rational(9, -4).denominator #=> 4
190
190
  # Rational(-2, -10).denominator #=> 5
191
- #
191
+ #
192
192
  def denominator: () -> Integer
193
193
 
194
194
  def div: (Numeric) -> Integer
@@ -200,34 +200,34 @@ class Rational < Numeric
200
200
  def eql?: (untyped) -> bool
201
201
 
202
202
  # Performs division and returns the value as a Float.
203
- #
203
+ #
204
204
  # Rational(2, 3).fdiv(1) #=> 0.6666666666666666
205
205
  # Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333
206
206
  # Rational(2).fdiv(3) #=> 0.6666666666666666
207
- #
207
+ #
208
208
  def fdiv: (Numeric) -> Float
209
209
 
210
210
  def finite?: () -> bool
211
211
 
212
212
  # Returns the largest number less than or equal to `rat` with a precision of
213
213
  # `ndigits` decimal digits (default: 0).
214
- #
214
+ #
215
215
  # When the precision is negative, the returned value is an integer with at least
216
216
  # `ndigits.abs` trailing zeros.
217
- #
217
+ #
218
218
  # Returns a rational when `ndigits` is positive, otherwise returns an integer.
219
- #
219
+ #
220
220
  # Rational(3).floor #=> 3
221
221
  # Rational(2, 3).floor #=> 0
222
222
  # Rational(-3, 2).floor #=> -2
223
- #
223
+ #
224
224
  # # decimal - 1 2 3 . 4 5 6
225
225
  # # ^ ^ ^ ^ ^ ^
226
226
  # # precision -3 -2 -1 0 +1 +2
227
- #
227
+ #
228
228
  # Rational('-123.456').floor(+1).to_f #=> -123.5
229
229
  # Rational('-123.456').floor(-1) #=> -130
230
- #
230
+ #
231
231
  def floor: () -> Integer
232
232
  | (Integer digits) -> (Integer | Rational)
233
233
 
@@ -242,40 +242,40 @@ class Rational < Numeric
242
242
  def infinite?: () -> Integer?
243
243
 
244
244
  # Returns the value as a string for inspection.
245
- #
245
+ #
246
246
  # Rational(2).inspect #=> "(2/1)"
247
247
  # Rational(-8, 6).inspect #=> "(-4/3)"
248
248
  # Rational('1/2').inspect #=> "(1/2)"
249
- #
249
+ #
250
250
  def inspect: () -> String
251
251
 
252
252
  def integer?: () -> bool
253
253
 
254
254
  # Returns the absolute value of `rat`.
255
- #
255
+ #
256
256
  # (1/2r).abs #=> (1/2)
257
257
  # (-1/2r).abs #=> (1/2)
258
- #
258
+ #
259
259
  # Rational#magnitude is an alias for Rational#abs.
260
- #
260
+ #
261
261
  alias magnitude abs
262
262
 
263
263
  def modulo: (Float) -> Float
264
264
  | (Numeric) -> Rational
265
265
 
266
266
  # Returns `true` if `rat` is less than 0.
267
- #
267
+ #
268
268
  def negative?: () -> bool
269
269
 
270
270
  def nonzero?: () -> self?
271
271
 
272
272
  # Returns the numerator.
273
- #
273
+ #
274
274
  # Rational(7).numerator #=> 7
275
275
  # Rational(7, 1).numerator #=> 7
276
276
  # Rational(9, -4).numerator #=> -9
277
277
  # Rational(-2, -10).numerator #=> 1
278
- #
278
+ #
279
279
  def numerator: () -> Integer
280
280
 
281
281
  alias phase angle
@@ -283,29 +283,29 @@ class Rational < Numeric
283
283
  def polar: () -> [ Rational, Integer | Float ]
284
284
 
285
285
  # Returns `true` if `rat` is greater than 0.
286
- #
286
+ #
287
287
  def positive?: () -> bool
288
288
 
289
289
  # Performs division.
290
- #
290
+ #
291
291
  # Rational(2, 3) / Rational(2, 3) #=> (1/1)
292
292
  # Rational(900) / Rational(1) #=> (900/1)
293
293
  # Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
294
294
  # Rational(9, 8) / 4 #=> (9/32)
295
295
  # Rational(20, 9) / 9.8 #=> 0.22675736961451246
296
- #
296
+ #
297
297
  def quo: (Float) -> Float
298
298
  | (Complex) -> Complex
299
299
  | (Numeric) -> Rational
300
300
 
301
301
  # Returns a simpler approximation of the value if the optional argument `eps` is
302
302
  # given (rat-|eps| <= result <= rat+|eps|), self otherwise.
303
- #
303
+ #
304
304
  # r = Rational(5033165, 16777216)
305
305
  # r.rationalize #=> (5033165/16777216)
306
306
  # r.rationalize(Rational('0.01')) #=> (3/10)
307
307
  # r.rationalize(Rational('0.1')) #=> (1/3)
308
- #
308
+ #
309
309
  def rationalize: (?Numeric eps) -> Rational
310
310
 
311
311
  def real: () -> Rational
@@ -321,25 +321,25 @@ class Rational < Numeric
321
321
 
322
322
  # Returns `rat` rounded to the nearest value with a precision of `ndigits`
323
323
  # decimal digits (default: 0).
324
- #
324
+ #
325
325
  # When the precision is negative, the returned value is an integer with at least
326
326
  # `ndigits.abs` trailing zeros.
327
- #
327
+ #
328
328
  # Returns a rational when `ndigits` is positive, otherwise returns an integer.
329
- #
329
+ #
330
330
  # Rational(3).round #=> 3
331
331
  # Rational(2, 3).round #=> 1
332
332
  # Rational(-3, 2).round #=> -2
333
- #
333
+ #
334
334
  # # decimal - 1 2 3 . 4 5 6
335
335
  # # ^ ^ ^ ^ ^ ^
336
336
  # # precision -3 -2 -1 0 +1 +2
337
- #
337
+ #
338
338
  # Rational('-123.456').round(+1).to_f #=> -123.5
339
339
  # Rational('-123.456').round(-1) #=> -120
340
- #
340
+ #
341
341
  # The optional `half` keyword argument is available similar to Float#round.
342
- #
342
+ #
343
343
  # Rational(25, 100).round(1, half: :up) #=> (3/10)
344
344
  # Rational(25, 100).round(1, half: :down) #=> (1/5)
345
345
  # Rational(25, 100).round(1, half: :even) #=> (1/5)
@@ -349,7 +349,7 @@ class Rational < Numeric
349
349
  # Rational(-25, 100).round(1, half: :up) #=> (-3/10)
350
350
  # Rational(-25, 100).round(1, half: :down) #=> (-1/5)
351
351
  # Rational(-25, 100).round(1, half: :even) #=> (-1/5)
352
- #
352
+ #
353
353
  def round: (?half: :up | :down | :even) -> Integer
354
354
  | (Integer digits, ?half: :up | :down | :even) -> (Integer | Rational)
355
355
 
@@ -361,62 +361,62 @@ class Rational < Numeric
361
361
  def to_c: () -> Complex
362
362
 
363
363
  # Returns the value as a Float.
364
- #
364
+ #
365
365
  # Rational(2).to_f #=> 2.0
366
366
  # Rational(9, 4).to_f #=> 2.25
367
367
  # Rational(-3, 4).to_f #=> -0.75
368
368
  # Rational(20, 3).to_f #=> 6.666666666666667
369
- #
369
+ #
370
370
  def to_f: () -> Float
371
371
 
372
372
  # Returns the truncated value as an integer.
373
- #
373
+ #
374
374
  # Equivalent to Rational#truncate.
375
- #
375
+ #
376
376
  # Rational(2, 3).to_i #=> 0
377
377
  # Rational(3).to_i #=> 3
378
378
  # Rational(300.6).to_i #=> 300
379
379
  # Rational(98, 71).to_i #=> 1
380
380
  # Rational(-31, 2).to_i #=> -15
381
- #
381
+ #
382
382
  def to_i: () -> Integer
383
383
 
384
384
  alias to_int to_i
385
385
 
386
386
  # Returns self.
387
- #
387
+ #
388
388
  # Rational(2).to_r #=> (2/1)
389
389
  # Rational(-8, 6).to_r #=> (-4/3)
390
- #
390
+ #
391
391
  def to_r: () -> Rational
392
392
 
393
393
  # Returns the value as a string.
394
- #
394
+ #
395
395
  # Rational(2).to_s #=> "2/1"
396
396
  # Rational(-8, 6).to_s #=> "-4/3"
397
397
  # Rational('1/2').to_s #=> "1/2"
398
- #
398
+ #
399
399
  def to_s: () -> String
400
400
 
401
401
  # Returns `rat` truncated (toward zero) to a precision of `ndigits` decimal
402
402
  # digits (default: 0).
403
- #
403
+ #
404
404
  # When the precision is negative, the returned value is an integer with at least
405
405
  # `ndigits.abs` trailing zeros.
406
- #
406
+ #
407
407
  # Returns a rational when `ndigits` is positive, otherwise returns an integer.
408
- #
408
+ #
409
409
  # Rational(3).truncate #=> 3
410
410
  # Rational(2, 3).truncate #=> 0
411
411
  # Rational(-3, 2).truncate #=> -1
412
- #
412
+ #
413
413
  # # decimal - 1 2 3 . 4 5 6
414
414
  # # ^ ^ ^ ^ ^ ^
415
415
  # # precision -3 -2 -1 0 +1 +2
416
- #
416
+ #
417
417
  # Rational('-123.456').truncate(+1).to_f #=> -123.4
418
418
  # Rational('-123.456').truncate(-1) #=> -120
419
- #
419
+ #
420
420
  def truncate: () -> Integer
421
421
  | (Integer ndigits) -> (Integer | Rational)
422
422