Module: T::Utils::Nilable
- Defined in:
- lib/types/utils.rb
Defined Under Namespace
Classes: TypeInfo
Constant Summary collapse
Class Method Summary collapse
- .get_type_info(prop_type) ⇒ Object
-
.get_underlying_type(prop_type) ⇒ Object
Get the underlying type inside prop_type: - if the type is A, the function returns A - if the type is T.nilable(A), the function returns A.
-
.get_underlying_type_object(prop_type) ⇒ Object
The difference between this function and the above function is that the Sorbet type, like T::Types::Simple is preserved.
- .is_union_with_nilclass(prop_type) ⇒ Object
Class Method Details
.get_type_info(prop_type) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/types/utils.rb', line 173 def self.get_type_info(prop_type) if prop_type.is_a?(T::Types::Union) non_nilable_type = prop_type.unwrap_nilable if non_nilable_type&.is_a?(T::Types::Simple) non_nilable_type = non_nilable_type.raw_type end TypeInfo.new(true, non_nilable_type) else TypeInfo.new(false, nil) end end |
.get_underlying_type(prop_type) ⇒ Object
Get the underlying type inside prop_type:
- if the type is A, the function returns A
- if the type is T.nilable(A), the function returns A
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/types/utils.rb', line 188 def self.(prop_type) if prop_type.is_a?(T::Types::Union) non_nilable_type = prop_type.unwrap_nilable if non_nilable_type&.is_a?(T::Types::Simple) non_nilable_type = non_nilable_type.raw_type end non_nilable_type || prop_type elsif prop_type.is_a?(T::Types::Simple) prop_type.raw_type else prop_type end end |
.get_underlying_type_object(prop_type) ⇒ Object
The difference between this function and the above function is that the Sorbet type, like T::Types::Simple is preserved.
204 205 206 |
# File 'lib/types/utils.rb', line 204 def self.(prop_type) T::Utils.unwrap_nilable(prop_type) || prop_type end |