Class: RBI::Type::All
Overview
A type that is intersection of multiple types like ‘T.all(String, Integer)`.
Instance Attribute Summary
Attributes inherited from Composite
Instance Method Summary collapse
-
#normalize ⇒ Object
: -> Type.
-
#simplify ⇒ Object
: -> Type.
-
#to_rbi ⇒ Object
: -> String.
Methods inherited from Composite
Methods inherited from RBI::Type
#==, all, any, anything, attached_class, boolean, class_of, #eql?, generic, #hash, #initialize, #nilable, nilable, #nilable?, #non_nilable, noreturn, parse_node, parse_string, proc, #rbs_string, self_type, shape, simple, t_class, #to_s, tuple, type_parameter, untyped, void
Constructor Details
This class inherits a constructor from RBI::Type::Composite
Instance Method Details
#normalize ⇒ Object
: -> Type
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/rbi/type.rb', line 393 def normalize flattened = @types.flat_map do |type| type = type.normalize case type when All type.types.map(&:normalize) else type end end.uniq if flattened.size == 1 return flattened.first #: as !nil end All.new(flattened) end |
#simplify ⇒ Object
: -> Type
413 414 415 416 417 418 419 420 421 422 |
# File 'lib/rbi/type.rb', line 413 def simplify type = normalize case type when All All.new(type.types.map(&:simplify)) else type.simplify end end |
#to_rbi ⇒ Object
: -> String
387 388 389 |
# File 'lib/rbi/type.rb', line 387 def to_rbi "T.all(#{@types.map(&:to_rbi).join(", ")})" end |