rbi 0.3.3 → 0.3.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.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/rbi/index.rb +3 -8
- data/lib/rbi/loc.rb +11 -0
- data/lib/rbi/model.rb +14 -38
- data/lib/rbi/parser.rb +101 -71
- data/lib/rbi/rbs/type_translator.rb +26 -30
- data/lib/rbi/rbs_printer.rb +99 -5
- data/lib/rbi/rewriters/attr_to_methods.rb +2 -1
- data/lib/rbi/rewriters/group_nodes.rb +16 -16
- data/lib/rbi/rewriters/merge_trees.rb +20 -11
- data/lib/rbi/rewriters/remove_known_definitions.rb +9 -3
- data/lib/rbi/rewriters/sort_nodes.rb +1 -1
- data/lib/rbi/type.rb +336 -100
- data/lib/rbi/type_parser.rb +7 -5
- data/lib/rbi/version.rb +1 -1
- data/lib/rbi/visitor.rb +1 -4
- data/lib/rbi.rb +0 -1
- data/rbi/rbi.rbi +242 -85
- metadata +2 -16
@@ -91,22 +91,22 @@ module RBI
|
|
91
91
|
@kind = kind
|
92
92
|
end
|
93
93
|
|
94
|
-
class Kind
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
94
|
+
class Kind
|
95
|
+
Mixins = new #: Kind
|
96
|
+
RequiredAncestors = new #: Kind
|
97
|
+
Helpers = new #: Kind
|
98
|
+
TypeMembers = new #: Kind
|
99
|
+
MixesInClassMethods = new #: Kind
|
100
|
+
Sends = new #: Kind
|
101
|
+
Attrs = new #: Kind
|
102
|
+
TStructFields = new #: Kind
|
103
|
+
TEnums = new #: Kind
|
104
|
+
Inits = new #: Kind
|
105
|
+
Methods = new #: Kind
|
106
|
+
SingletonClasses = new #: Kind
|
107
|
+
Consts = new #: Kind
|
108
|
+
|
109
|
+
private_class_method(:new)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -37,12 +37,12 @@ module RBI
|
|
37
37
|
# end
|
38
38
|
# ~~~
|
39
39
|
class Merge
|
40
|
-
class Keep
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
class Keep
|
41
|
+
NONE = new #: Keep
|
42
|
+
LEFT = new #: Keep
|
43
|
+
RIGHT = new #: Keep
|
44
|
+
|
45
|
+
private_class_method(:new)
|
46
46
|
end
|
47
47
|
|
48
48
|
class << self
|
@@ -79,11 +79,20 @@ module RBI
|
|
79
79
|
end
|
80
80
|
|
81
81
|
# Used for logging / error displaying purpose
|
82
|
-
class Conflict
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
class Conflict
|
83
|
+
#: Node
|
84
|
+
attr_reader :left, :right
|
85
|
+
|
86
|
+
#: String
|
87
|
+
attr_reader :left_name, :right_name
|
88
|
+
|
89
|
+
#: (left: Node, right: Node, left_name: String, right_name: String) -> void
|
90
|
+
def initialize(left:, right:, left_name:, right_name:)
|
91
|
+
@left = left
|
92
|
+
@right = right
|
93
|
+
@left_name = left_name
|
94
|
+
@right_name = right_name
|
95
|
+
end
|
87
96
|
|
88
97
|
#: -> String
|
89
98
|
def to_s
|
@@ -123,9 +123,15 @@ module RBI
|
|
123
123
|
@operations << Operation.new(deleted_node: node, duplicate_of: previous)
|
124
124
|
end
|
125
125
|
|
126
|
-
class Operation
|
127
|
-
|
128
|
-
|
126
|
+
class Operation
|
127
|
+
#: Node
|
128
|
+
attr_reader :deleted_node, :duplicate_of
|
129
|
+
|
130
|
+
#: (deleted_node: Node, duplicate_of: Node) -> void
|
131
|
+
def initialize(deleted_node:, duplicate_of:)
|
132
|
+
@deleted_node = deleted_node
|
133
|
+
@duplicate_of = duplicate_of
|
134
|
+
end
|
129
135
|
|
130
136
|
#: -> String
|
131
137
|
def to_s
|
data/lib/rbi/type.rb
CHANGED
@@ -3,12 +3,8 @@
|
|
3
3
|
|
4
4
|
module RBI
|
5
5
|
# The base class for all RBI types.
|
6
|
+
# @abstract
|
6
7
|
class Type
|
7
|
-
extend T::Sig
|
8
|
-
extend T::Helpers
|
9
|
-
|
10
|
-
abstract!
|
11
|
-
|
12
8
|
# Simple
|
13
9
|
|
14
10
|
# A type that represents a simple class name like `String` or `Foo`.
|
@@ -35,6 +31,18 @@ module RBI
|
|
35
31
|
def to_rbi
|
36
32
|
@name
|
37
33
|
end
|
34
|
+
|
35
|
+
# @override
|
36
|
+
#: -> Type
|
37
|
+
def normalize
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# @override
|
42
|
+
#: -> Type
|
43
|
+
def simplify
|
44
|
+
self
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
40
48
|
# Literals
|
@@ -52,6 +60,18 @@ module RBI
|
|
52
60
|
def to_rbi
|
53
61
|
"T.anything"
|
54
62
|
end
|
63
|
+
|
64
|
+
# @override
|
65
|
+
#: -> Type
|
66
|
+
def normalize
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
# @override
|
71
|
+
#: -> Type
|
72
|
+
def simplify
|
73
|
+
self
|
74
|
+
end
|
55
75
|
end
|
56
76
|
|
57
77
|
# `T.attached_class`.
|
@@ -67,6 +87,18 @@ module RBI
|
|
67
87
|
def to_rbi
|
68
88
|
"T.attached_class"
|
69
89
|
end
|
90
|
+
|
91
|
+
# @override
|
92
|
+
#: -> Type
|
93
|
+
def normalize
|
94
|
+
self
|
95
|
+
end
|
96
|
+
|
97
|
+
# @override
|
98
|
+
#: -> Type
|
99
|
+
def simplify
|
100
|
+
self
|
101
|
+
end
|
70
102
|
end
|
71
103
|
|
72
104
|
# `T::Boolean`.
|
@@ -82,6 +114,18 @@ module RBI
|
|
82
114
|
def to_rbi
|
83
115
|
"T::Boolean"
|
84
116
|
end
|
117
|
+
|
118
|
+
# @override
|
119
|
+
#: -> Type
|
120
|
+
def normalize
|
121
|
+
Type::Any.new([Type.simple("TrueClass"), Type.simple("FalseClass")])
|
122
|
+
end
|
123
|
+
|
124
|
+
# @override
|
125
|
+
#: -> Type
|
126
|
+
def simplify
|
127
|
+
self
|
128
|
+
end
|
85
129
|
end
|
86
130
|
|
87
131
|
# `T.noreturn`.
|
@@ -97,6 +141,18 @@ module RBI
|
|
97
141
|
def to_rbi
|
98
142
|
"T.noreturn"
|
99
143
|
end
|
144
|
+
|
145
|
+
# @override
|
146
|
+
#: -> Type
|
147
|
+
def normalize
|
148
|
+
self
|
149
|
+
end
|
150
|
+
|
151
|
+
# @override
|
152
|
+
#: -> Type
|
153
|
+
def simplify
|
154
|
+
self
|
155
|
+
end
|
100
156
|
end
|
101
157
|
|
102
158
|
# `T.self_type`.
|
@@ -112,6 +168,18 @@ module RBI
|
|
112
168
|
def to_rbi
|
113
169
|
"T.self_type"
|
114
170
|
end
|
171
|
+
|
172
|
+
# @override
|
173
|
+
#: -> Type
|
174
|
+
def normalize
|
175
|
+
self
|
176
|
+
end
|
177
|
+
|
178
|
+
# @override
|
179
|
+
#: -> Type
|
180
|
+
def simplify
|
181
|
+
self
|
182
|
+
end
|
115
183
|
end
|
116
184
|
|
117
185
|
# `T.untyped`.
|
@@ -127,6 +195,18 @@ module RBI
|
|
127
195
|
def to_rbi
|
128
196
|
"T.untyped"
|
129
197
|
end
|
198
|
+
|
199
|
+
# @override
|
200
|
+
#: -> Type
|
201
|
+
def normalize
|
202
|
+
self
|
203
|
+
end
|
204
|
+
|
205
|
+
# @override
|
206
|
+
#: -> Type
|
207
|
+
def simplify
|
208
|
+
self
|
209
|
+
end
|
130
210
|
end
|
131
211
|
|
132
212
|
# `void`.
|
@@ -142,6 +222,18 @@ module RBI
|
|
142
222
|
def to_rbi
|
143
223
|
"void"
|
144
224
|
end
|
225
|
+
|
226
|
+
# @override
|
227
|
+
#: -> Type
|
228
|
+
def normalize
|
229
|
+
self
|
230
|
+
end
|
231
|
+
|
232
|
+
# @override
|
233
|
+
#: -> Type
|
234
|
+
def simplify
|
235
|
+
self
|
236
|
+
end
|
145
237
|
end
|
146
238
|
|
147
239
|
# Composites
|
@@ -168,6 +260,18 @@ module RBI
|
|
168
260
|
def to_rbi
|
169
261
|
"T::Class[#{@type}]"
|
170
262
|
end
|
263
|
+
|
264
|
+
# @override
|
265
|
+
#: -> Type
|
266
|
+
def normalize
|
267
|
+
self
|
268
|
+
end
|
269
|
+
|
270
|
+
# @override
|
271
|
+
#: -> Type
|
272
|
+
def simplify
|
273
|
+
self
|
274
|
+
end
|
171
275
|
end
|
172
276
|
|
173
277
|
# The singleton class of another type like `T.class_of(Foo)`.
|
@@ -200,6 +304,18 @@ module RBI
|
|
200
304
|
"T.class_of(#{@type.to_rbi})"
|
201
305
|
end
|
202
306
|
end
|
307
|
+
|
308
|
+
# @override
|
309
|
+
#: -> Type
|
310
|
+
def normalize
|
311
|
+
self
|
312
|
+
end
|
313
|
+
|
314
|
+
# @override
|
315
|
+
#: -> Type
|
316
|
+
def simplify
|
317
|
+
self
|
318
|
+
end
|
203
319
|
end
|
204
320
|
|
205
321
|
# A type that can be `nil` like `T.nilable(String)`.
|
@@ -224,14 +340,30 @@ module RBI
|
|
224
340
|
def to_rbi
|
225
341
|
"T.nilable(#{@type.to_rbi})"
|
226
342
|
end
|
343
|
+
|
344
|
+
# @override
|
345
|
+
#: -> Type
|
346
|
+
def normalize
|
347
|
+
Type::Any.new([Type.simple("NilClass"), @type.normalize])
|
348
|
+
end
|
349
|
+
|
350
|
+
# @override
|
351
|
+
#: -> Type
|
352
|
+
def simplify
|
353
|
+
case @type
|
354
|
+
when Nilable
|
355
|
+
@type.simplify
|
356
|
+
when Untyped
|
357
|
+
@type.simplify
|
358
|
+
else
|
359
|
+
self
|
360
|
+
end
|
361
|
+
end
|
227
362
|
end
|
228
363
|
|
229
364
|
# A type that is composed of multiple types like `T.all(String, Integer)`.
|
365
|
+
# @abstract
|
230
366
|
class Composite < Type
|
231
|
-
extend T::Helpers
|
232
|
-
|
233
|
-
abstract!
|
234
|
-
|
235
367
|
#: Array[Type]
|
236
368
|
attr_reader :types
|
237
369
|
|
@@ -255,6 +387,39 @@ module RBI
|
|
255
387
|
def to_rbi
|
256
388
|
"T.all(#{@types.map(&:to_rbi).join(", ")})"
|
257
389
|
end
|
390
|
+
|
391
|
+
# @override
|
392
|
+
#: -> Type
|
393
|
+
def normalize
|
394
|
+
flattened = @types.flat_map do |type|
|
395
|
+
type = type.normalize
|
396
|
+
case type
|
397
|
+
when All
|
398
|
+
type.types.map(&:normalize)
|
399
|
+
else
|
400
|
+
type
|
401
|
+
end
|
402
|
+
end.uniq
|
403
|
+
|
404
|
+
if flattened.size == 1
|
405
|
+
return flattened.first #: as !nil
|
406
|
+
end
|
407
|
+
|
408
|
+
All.new(flattened)
|
409
|
+
end
|
410
|
+
|
411
|
+
# @override
|
412
|
+
#: -> Type
|
413
|
+
def simplify
|
414
|
+
type = normalize
|
415
|
+
|
416
|
+
case type
|
417
|
+
when All
|
418
|
+
All.new(type.types.map(&:simplify))
|
419
|
+
else
|
420
|
+
type.simplify
|
421
|
+
end
|
422
|
+
end
|
258
423
|
end
|
259
424
|
|
260
425
|
# A type that is union of multiple types like `T.any(String, Integer)`.
|
@@ -269,6 +434,75 @@ module RBI
|
|
269
434
|
def nilable?
|
270
435
|
@types.any? { |type| type.nilable? || (type.is_a?(Simple) && type.name == "NilClass") }
|
271
436
|
end
|
437
|
+
|
438
|
+
# @override
|
439
|
+
#: -> Type
|
440
|
+
def normalize
|
441
|
+
flattened = @types.flat_map do |type|
|
442
|
+
type = type.normalize
|
443
|
+
case type
|
444
|
+
when Any
|
445
|
+
type.types.map(&:normalize)
|
446
|
+
else
|
447
|
+
type
|
448
|
+
end
|
449
|
+
end.uniq
|
450
|
+
|
451
|
+
if flattened.size == 1
|
452
|
+
flattened.first #: as !nil
|
453
|
+
else
|
454
|
+
Any.new(flattened)
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
# @override
|
459
|
+
#: -> Type
|
460
|
+
def simplify
|
461
|
+
type = normalize
|
462
|
+
return type.simplify unless type.is_a?(Any)
|
463
|
+
|
464
|
+
types = type.types.map(&:simplify)
|
465
|
+
return Untyped.new if types.any? { |type| type.is_a?(Untyped) }
|
466
|
+
|
467
|
+
has_true_class = types.any? { |type| type.is_a?(Simple) && type.name == "TrueClass" }
|
468
|
+
has_false_class = types.any? { |type| type.is_a?(Simple) && type.name == "FalseClass" }
|
469
|
+
|
470
|
+
if has_true_class && has_false_class
|
471
|
+
types = types.reject { |type| type.is_a?(Simple) && (type.name == "TrueClass" || type.name == "FalseClass") }
|
472
|
+
types << Type.boolean
|
473
|
+
end
|
474
|
+
|
475
|
+
is_nilable = false #: bool
|
476
|
+
|
477
|
+
types = types.filter_map do |type|
|
478
|
+
case type
|
479
|
+
when Simple
|
480
|
+
if type.name == "NilClass"
|
481
|
+
is_nilable = true
|
482
|
+
nil
|
483
|
+
else
|
484
|
+
type
|
485
|
+
end
|
486
|
+
when Nilable
|
487
|
+
is_nilable = true
|
488
|
+
type.type
|
489
|
+
else
|
490
|
+
type
|
491
|
+
end
|
492
|
+
end.uniq
|
493
|
+
|
494
|
+
final_type = if types.size == 1
|
495
|
+
types.first #: as !nil
|
496
|
+
else
|
497
|
+
Any.new(types)
|
498
|
+
end
|
499
|
+
|
500
|
+
if is_nilable
|
501
|
+
return Nilable.new(final_type)
|
502
|
+
end
|
503
|
+
|
504
|
+
final_type
|
505
|
+
end
|
272
506
|
end
|
273
507
|
|
274
508
|
# Generics
|
@@ -299,6 +533,18 @@ module RBI
|
|
299
533
|
def to_rbi
|
300
534
|
"#{@name}[#{@params.map(&:to_rbi).join(", ")}]"
|
301
535
|
end
|
536
|
+
|
537
|
+
# @override
|
538
|
+
#: -> Type
|
539
|
+
def normalize
|
540
|
+
self
|
541
|
+
end
|
542
|
+
|
543
|
+
# @override
|
544
|
+
#: -> Type
|
545
|
+
def simplify
|
546
|
+
self
|
547
|
+
end
|
302
548
|
end
|
303
549
|
|
304
550
|
# A type parameter like `T.type_parameter(:U)`.
|
@@ -323,6 +569,18 @@ module RBI
|
|
323
569
|
def to_rbi
|
324
570
|
"T.type_parameter(#{@name.inspect})"
|
325
571
|
end
|
572
|
+
|
573
|
+
# @override
|
574
|
+
#: -> Type
|
575
|
+
def normalize
|
576
|
+
self
|
577
|
+
end
|
578
|
+
|
579
|
+
# @override
|
580
|
+
#: -> Type
|
581
|
+
def simplify
|
582
|
+
self
|
583
|
+
end
|
326
584
|
end
|
327
585
|
|
328
586
|
# Tuples and shapes
|
@@ -349,6 +607,18 @@ module RBI
|
|
349
607
|
def to_rbi
|
350
608
|
"[#{@types.map(&:to_rbi).join(", ")}]"
|
351
609
|
end
|
610
|
+
|
611
|
+
# @override
|
612
|
+
#: -> Type
|
613
|
+
def normalize
|
614
|
+
self
|
615
|
+
end
|
616
|
+
|
617
|
+
# @override
|
618
|
+
#: -> Type
|
619
|
+
def simplify
|
620
|
+
self
|
621
|
+
end
|
352
622
|
end
|
353
623
|
|
354
624
|
# A shape type like `{name: String, age: Integer}`.
|
@@ -377,6 +647,18 @@ module RBI
|
|
377
647
|
"{ " + @types.map { |name, type| "#{name}: #{type.to_rbi}" }.join(", ") + " }"
|
378
648
|
end
|
379
649
|
end
|
650
|
+
|
651
|
+
# @override
|
652
|
+
#: -> Type
|
653
|
+
def normalize
|
654
|
+
self
|
655
|
+
end
|
656
|
+
|
657
|
+
# @override
|
658
|
+
#: -> Type
|
659
|
+
def simplify
|
660
|
+
self
|
661
|
+
end
|
380
662
|
end
|
381
663
|
|
382
664
|
# Proc
|
@@ -459,6 +741,18 @@ module RBI
|
|
459
741
|
|
460
742
|
rbi
|
461
743
|
end
|
744
|
+
|
745
|
+
# @override
|
746
|
+
#: -> Type
|
747
|
+
def normalize
|
748
|
+
self
|
749
|
+
end
|
750
|
+
|
751
|
+
# @override
|
752
|
+
#: -> Type
|
753
|
+
def simplify
|
754
|
+
self
|
755
|
+
end
|
462
756
|
end
|
463
757
|
|
464
758
|
# Type builder
|
@@ -541,14 +835,8 @@ module RBI
|
|
541
835
|
# it may return something other than a `RBI::Type::Nilable`.
|
542
836
|
#: (Type type) -> Type
|
543
837
|
def nilable(type)
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
if type.nilable?
|
548
|
-
type
|
549
|
-
else
|
550
|
-
Nilable.new(type)
|
551
|
-
end
|
838
|
+
nilable = Nilable.new(type)
|
839
|
+
nilable.simplify
|
552
840
|
end
|
553
841
|
|
554
842
|
# Builds a type that represents an intersection of multiple types like `T.all(String, Integer)`.
|
@@ -557,25 +845,7 @@ module RBI
|
|
557
845
|
# it may return something other than a `All`.
|
558
846
|
#: (Type type1, Type type2, *Type types) -> Type
|
559
847
|
def all(type1, type2, *types)
|
560
|
-
|
561
|
-
|
562
|
-
# TODO: should we move this logic to a `flatten!`, `normalize!` or `simplify!` method?
|
563
|
-
flattened = types.flatten.flat_map do |type|
|
564
|
-
case type
|
565
|
-
when All
|
566
|
-
type.types
|
567
|
-
else
|
568
|
-
type
|
569
|
-
end
|
570
|
-
end.uniq
|
571
|
-
|
572
|
-
if flattened.size == 1
|
573
|
-
flattened.first #: as !nil
|
574
|
-
else
|
575
|
-
raise ArgumentError, "RBI::Type.all should have at least 2 types supplied" if flattened.size < 2
|
576
|
-
|
577
|
-
All.new(flattened)
|
578
|
-
end
|
848
|
+
All.new([type1, type2, *types]).simplify
|
579
849
|
end
|
580
850
|
|
581
851
|
# Builds a type that represents a union of multiple types like `T.any(String, Integer)`.
|
@@ -584,64 +854,7 @@ module RBI
|
|
584
854
|
# it may return something other than a `Any`.
|
585
855
|
#: (Type type1, Type type2, *Type types) -> Type
|
586
856
|
def any(type1, type2, *types)
|
587
|
-
|
588
|
-
|
589
|
-
# TODO: should we move this logic to a `flatten!`, `normalize!` or `simplify!` method?
|
590
|
-
flattened = types.flatten.flat_map do |type|
|
591
|
-
case type
|
592
|
-
when Any
|
593
|
-
type.types
|
594
|
-
else
|
595
|
-
type
|
596
|
-
end
|
597
|
-
end
|
598
|
-
|
599
|
-
is_nilable = false #: bool
|
600
|
-
|
601
|
-
types = flattened.filter_map do |type|
|
602
|
-
case type
|
603
|
-
when Simple
|
604
|
-
if type.name == "NilClass"
|
605
|
-
is_nilable = true
|
606
|
-
nil
|
607
|
-
else
|
608
|
-
type
|
609
|
-
end
|
610
|
-
when Nilable
|
611
|
-
is_nilable = true
|
612
|
-
type.type
|
613
|
-
else
|
614
|
-
type
|
615
|
-
end
|
616
|
-
end.uniq
|
617
|
-
|
618
|
-
has_true_class = types.any? { |type| type.is_a?(Simple) && type.name == "TrueClass" }
|
619
|
-
has_false_class = types.any? { |type| type.is_a?(Simple) && type.name == "FalseClass" }
|
620
|
-
|
621
|
-
if has_true_class && has_false_class
|
622
|
-
types = types.reject { |type| type.is_a?(Simple) && (type.name == "TrueClass" || type.name == "FalseClass") }
|
623
|
-
types << boolean
|
624
|
-
end
|
625
|
-
|
626
|
-
type = case types.size
|
627
|
-
when 0
|
628
|
-
if is_nilable
|
629
|
-
is_nilable = false
|
630
|
-
simple("NilClass")
|
631
|
-
else
|
632
|
-
raise ArgumentError, "RBI::Type.any should have at least 2 types supplied"
|
633
|
-
end
|
634
|
-
when 1
|
635
|
-
types.first #: as !nil
|
636
|
-
else
|
637
|
-
Any.new(types)
|
638
|
-
end
|
639
|
-
|
640
|
-
if is_nilable
|
641
|
-
nilable(type)
|
642
|
-
else
|
643
|
-
type
|
644
|
-
end
|
857
|
+
Any.new([type1, type2, *types]).simplify
|
645
858
|
end
|
646
859
|
|
647
860
|
# Generics
|
@@ -649,7 +862,7 @@ module RBI
|
|
649
862
|
# Builds a type that represents a generic type like `T::Array[String]` or `T::Hash[Symbol, Integer]`.
|
650
863
|
#: (String name, *(Type | Array[Type]) params) -> Generic
|
651
864
|
def generic(name, *params)
|
652
|
-
|
865
|
+
Generic.new(name, *params.flatten)
|
653
866
|
end
|
654
867
|
|
655
868
|
# Builds a type that represents a type parameter like `T.type_parameter(:U)`.
|
@@ -680,9 +893,6 @@ module RBI
|
|
680
893
|
Proc.new
|
681
894
|
end
|
682
895
|
|
683
|
-
# We mark the constructor as `protected` because we want to force the use of factories on `Type` to create types
|
684
|
-
protected :new
|
685
|
-
|
686
896
|
private
|
687
897
|
|
688
898
|
#: (String name) -> bool
|
@@ -737,7 +947,32 @@ module RBI
|
|
737
947
|
is_a?(Nilable)
|
738
948
|
end
|
739
949
|
|
740
|
-
|
950
|
+
# Returns a normalized version of the type.
|
951
|
+
#
|
952
|
+
# Normalized types are meant to be easier to process, not to read.
|
953
|
+
# For example, `T.any(TrueClass, FalseClass)` instead of `T::Boolean` or
|
954
|
+
# `T.any(String, NilClass)` instead of `T.nilable(String)`.
|
955
|
+
#
|
956
|
+
# This is the inverse of `#simplify`.
|
957
|
+
#
|
958
|
+
# @abstract
|
959
|
+
#: -> Type
|
960
|
+
def normalize; end
|
961
|
+
|
962
|
+
# Returns a simplified version of the type.
|
963
|
+
#
|
964
|
+
# Simplified types are meant to be easier to read, not to process.
|
965
|
+
# For example, `T::Boolean` instead of `T.any(TrueClass, FalseClass)` or
|
966
|
+
# `T.nilable(String)` instead of `T.any(String, NilClass)`.
|
967
|
+
#
|
968
|
+
# This is the inverse of `#normalize`.
|
969
|
+
#
|
970
|
+
# @abstract
|
971
|
+
#: -> Type
|
972
|
+
def simplify; end
|
973
|
+
|
974
|
+
# @abstract
|
975
|
+
#: (BasicObject) -> bool
|
741
976
|
def ==(other); end
|
742
977
|
|
743
978
|
#: (BasicObject other) -> bool
|
@@ -751,7 +986,8 @@ module RBI
|
|
751
986
|
to_rbi.hash
|
752
987
|
end
|
753
988
|
|
754
|
-
|
989
|
+
# @abstract
|
990
|
+
#: -> String
|
755
991
|
def to_rbi; end
|
756
992
|
|
757
993
|
# @override
|