class T::Types::Union
Takes a list of types. Validates that an object matches at least one of the types.
def initialize(types)
def initialize(types) @types = types.flat_map do |type| if type.is_a?(Union) # Simplify nested unions (mostly so `name` returns a nicer value) type.types else T::Utils.coerce(type) end end.uniq end
def name
def name type_shortcuts(@types) 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 type_shortcuts(types)
def type_shortcuts(types) es.size == 1 rn types[0].name e = T::Utils.coerce(NilClass) ass = T::Utils.coerce(TrueClass) lass = T::Utils.coerce(FalseClass) es.any? {|t| t == nilable} ining_types = types.reject {|t| t == nilable} ilable(#{type_shortcuts(remaining_types)})" types.any? {|t| t == trueclass} && types.any? {|t| t == falseclass} ining_types = types.reject {|t| t == trueclass || t == falseclass} _shortcuts([T::Private::Types::StringHolder.new("T::Boolean")] + remaining_types) s = types.map(&:name).compact.sort ny(#{names.join(', ')})"
def valid?(obj)
def valid?(obj) @types.each do |type| return true if type.valid?(obj) end false end