class T::Types::Simple

Validates that an object belongs to the specified class.

def error_message(obj)

overrides Base
def error_message(obj)
message = super(obj)
_name = obj.class.name
 error_message unless name == actual_name
.strip
ror_message}
expected type and received object type have the same name but refer to different constants.
cted type is #{name} with object id #{@raw_type.__id__}, but received type is #{actual_name} with object id #{obj.class.__id__}.
e might be a constant reloading problem in your application.

def initialize(raw_type)

def initialize(raw_type)
  @raw_type = raw_type
end

def name

overrides Base
def name
  # Memoize to mitigate pathological performance with anonymous modules (https://bugs.ruby-lang.org/issues/11119)
  #
  # `name` isn't normally a hot path for types, but it is used in initializing a T::Types::Union,
  # and so in `T.nilable`, and so in runtime constructions like `x = T.let(nil, T.nilable(Integer))`.
  @name ||= (NAME_METHOD.bind(@raw_type).call || @raw_type.name).freeze
end

def subtype_of_single?(other)

overrides Base
def subtype_of_single?(other)
ther
imple
_type <= other.raw_type
ypedClass
is case is a bit odd--we would have liked to solve this like we do
r `T::Array` et al., but don't for backwards compatibility.
e `type_for_module` below.
_type <= other.underlying_class
e

def to_nilable

def to_nilable
  @nilable ||= T::Private::Types::SimplePairUnion.new(
    self,
    T::Utils::Nilable::NIL_TYPE,
  )
end

def valid?(obj)

overrides Base
def valid?(obj)
  obj.is_a?(@raw_type)
end