class T::Types::Simple

Validates that an object belongs to the specified class.

Attributes

raw_type[R]

Public Class Methods

new(raw_type) click to toggle source
# File lib/types/types/simple.rb, line 9
def initialize(raw_type)
  @raw_type = raw_type
end

Public Instance Methods

name() click to toggle source

@override Base

# File lib/types/types/simple.rb, line 14
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 ||= @raw_type.name.freeze
end
to_nilable() click to toggle source
# File lib/types/types/simple.rb, line 37
def to_nilable
  @nilable ||= T::Types::Union.new([self, T::Utils::Nilable::NIL_TYPE])
end
valid?(obj) click to toggle source

@override Base

# File lib/types/types/simple.rb, line 23
def valid?(obj)
  obj.is_a?(@raw_type)
end

Private Instance Methods

subtype_of_single?(other) click to toggle source

@override Base

# File lib/types/types/simple.rb, line 28
        def subtype_of_single?(other)
  case other
  when Simple
    @raw_type <= other.raw_type
  else
    false
  end
end