class T::Private::Types::SimplePairUnion
This covers e.g. T.nilable(SomeModule), T.any(Integer, Float), and T::Boolean.
Specialization of Union for the common case of the union of two simple types.
def initialize(type_a, type_b)
-
type_b
(T::Types::Simple
) -- -
type_a
(T::Types::Simple
) --
def initialize(type_a, type_b) if type_a == type_b raise DuplicateType.new("#{type_a} == #{type_b}") end @raw_a = type_a.raw_type @raw_b = type_b.raw_type end
def recursively_valid?(obj)
def recursively_valid?(obj) obj.is_a?(@raw_a) || obj.is_a?(@raw_b) end
def types
def types # We reconstruct the simple types rather than just storing them because # (1) this is normally not a hot path and (2) we want to keep the instance # variable count <= 3 so that we can fit in a 40 byte heap entry along # with object headers. @types ||= [ T::Types::Simple::Private::Pool.type_for_module(@raw_a), T::Types::Simple::Private::Pool.type_for_module(@raw_b), ] end
def valid?(obj)
def valid?(obj) obj.is_a?(@raw_a) || obj.is_a?(@raw_b) end