Class: Tapioca::TypeVariableModule
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/sorbet_ext/generic_name_patch.rb
Overview
This is subclassing from Module so that instances of this type will be modules. The reason why we want that is because that means those instances will automatically get bound to the constant names they are assigned to by Ruby. As a result, we don’t need to do any matching of constants to type variables to bind their names, Ruby will do that automatically for us and we get the name method for free from Module.
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #coerce_to_type_variable ⇒ Object
- #fixed? ⇒ Boolean
-
#initialize(context, type, variance, fixed, lower, upper, bounds_proc) ⇒ TypeVariableModule
constructor
A new instance of TypeVariableModule.
- #name ⇒ Object
- #serialize ⇒ Object
Methods inherited from Module
#autoload, #autoload_without_tapioca
Constructor Details
#initialize(context, type, variance, fixed, lower, upper, bounds_proc) ⇒ TypeVariableModule
Returns a new instance of TypeVariableModule.
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 177 def initialize(context, type, variance, fixed, lower, upper, bounds_proc) @context = context @type = type @variance = variance @bounds_proc = if bounds_proc bounds_proc else build_bounds_proc(fixed, lower, upper) end super() end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
163 164 165 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 163 def type @type end |
Instance Method Details
#coerce_to_type_variable ⇒ Object
218 219 220 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 218 def coerce_to_type_variable TypeVariable.new(name, @variance) end |
#fixed? ⇒ Boolean
198 199 200 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 198 def fixed? bounds.key?(:fixed) end |
#name ⇒ Object
192 193 194 195 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 192 def name constant_name = super constant_name&.split("::")&.last end |
#serialize ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 203 def serialize fixed = bounds[:fixed].to_s if fixed? lower = bounds[:lower].to_s if bounds.key?(:lower) upper = bounds[:upper].to_s if bounds.key?(:upper) RBIHelper.serialize_type_variable( @type.serialize, @variance, fixed, upper, lower, ) end |