class T::Types::Intersection
Takes a list of types. Validates that an object matches all of the types.
def initialize(types)
def initialize(types) @types = types.flat_map do |type| type = T::Utils.resolve_alias(type) if type.is_a?(Intersection) # Simplify nested intersections (mostly so `name` returns a nicer value) type.types else T::Utils.coerce(type) end end.uniq end
def name
def name "T.all(#{@types.map(&:name).sort.join(', ')})" end
def recursively_valid?(obj)
def recursively_valid?(obj) @types.all? {|type| type.recursively_valid?(obj)} end
def subtype_of_single?(other)
def subtype_of_single?(other) "This should never be reached if you're going through `subtype_of?` (and you should be)"
def valid?(obj)
def valid?(obj) @types.all? {|type| type.valid?(obj)} end