Class: T::Types::Simple
Overview
Validates that an object belongs to the specified class.
Defined Under Namespace
Modules: Private
Instance Attribute Summary collapse
-
#raw_type ⇒ Object
readonly
Returns the value of attribute raw_type.
Instance Method Summary collapse
-
#initialize(raw_type) ⇒ Simple
constructor
A new instance of Simple.
-
#name ⇒ Object
overrides Base.
- #to_nilable ⇒ Object
-
#valid?(obj) ⇒ Boolean
overrides Base.
Methods inherited from Base
#==, #describe_obj, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #recursively_valid?, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(raw_type) ⇒ Simple
Returns a new instance of Simple.
9 10 11 |
# File 'lib/types/types/simple.rb', line 9 def initialize(raw_type) @raw_type = raw_type end |
Instance Attribute Details
#raw_type ⇒ Object (readonly)
Returns the value of attribute raw_type.
7 8 9 |
# File 'lib/types/types/simple.rb', line 7 def raw_type @raw_type end |
Instance Method Details
#name ⇒ Object
overrides Base
14 15 16 17 18 19 20 |
# 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 ⇒ Object
54 55 56 57 58 59 |
# File 'lib/types/types/simple.rb', line 54 def to_nilable @nilable ||= T::Private::Types::SimplePairUnion.new( self, T::Utils::Nilable::NIL_TYPE, ) end |
#valid?(obj) ⇒ Boolean
overrides Base
23 24 25 |
# File 'lib/types/types/simple.rb', line 23 def valid?(obj) obj.is_a?(@raw_type) end |