Class: RBI::Type::All

Inherits:
Composite show all
Defined in:
lib/rbi/type.rb

Overview

A type that is intersection of multiple types like ‘T.all(String, Integer)`.

Instance Attribute Summary

Attributes inherited from Composite

#types

Instance Method Summary collapse

Methods inherited from Composite

#==, #initialize

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, t_module, #to_s, tuple, type_alias, type_parameter, untyped, void

Constructor Details

This class inherits a constructor from RBI::Type::Composite

Instance Method Details

#normalizeObject

: -> Type



429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/rbi/type.rb', line 429

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

#simplifyObject

: -> Type



449
450
451
452
453
454
455
456
457
458
# File 'lib/rbi/type.rb', line 449

def simplify
  type = normalize

  case type
  when All
    All.new(type.types.map(&:simplify))
  else
    type.simplify
  end
end

#to_rbiObject

: -> String



423
424
425
# File 'lib/rbi/type.rb', line 423

def to_rbi
  "::T.all(#{@types.map(&:to_rbi).join(", ")})"
end