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
- #build_type ⇒ Object
-
#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.
12 13 14 |
# File 'lib/types/types/simple.rb', line 12 def initialize(raw_type) @raw_type = raw_type end |
Instance Attribute Details
#raw_type ⇒ Object (readonly)
Returns the value of attribute raw_type.
10 11 12 |
# File 'lib/types/types/simple.rb', line 10 def raw_type @raw_type end |
Instance Method Details
#build_type ⇒ Object
16 17 18 |
# File 'lib/types/types/simple.rb', line 16 def build_type nil end |
#name ⇒ Object
overrides Base
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/types/types/simple.rb', line 21 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))`. # # Care more about back compat than we do about performance here. # Once 2.6 is well in the rear view mirror, we can replace this. # rubocop:disable Performance/BindCall @name ||= (NAME_METHOD.bind(@raw_type).call || @raw_type.name).freeze # rubocop:enable Performance/BindCall end |
#to_nilable ⇒ Object
71 72 73 74 75 76 |
# File 'lib/types/types/simple.rb', line 71 def to_nilable @nilable ||= T::Private::Types::SimplePairUnion.new( self, T::Utils::Nilable::NIL_TYPE, ) end |
#valid?(obj) ⇒ Boolean
overrides Base
35 36 37 |
# File 'lib/types/types/simple.rb', line 35 def valid?(obj) obj.is_a?(@raw_type) end |