Class: Tapioca::TypeVariableModule
- 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
Constant Summary collapse
- DEFAULT_BOUNDS_PROC =
: ^-> Hash[Symbol, untyped]
-> { {} }
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
: Type.
Instance Method Summary collapse
-
#coerce_to_type_variable ⇒ Object
: -> Tapioca::TypeVariable.
-
#fixed? ⇒ Boolean
: -> bool.
-
#initialize(context, type, variance, bounds_proc) ⇒ TypeVariableModule
constructor
: (T::Module context, Type type, Symbol variance, (^-> Hash[Symbol, untyped])? bounds_proc) -> void.
-
#name ⇒ Object
: -> String?.
-
#serialize ⇒ Object
: -> String.
Methods inherited from Module
#autoload, #autoload_without_tapioca
Constructor Details
#initialize(context, type, variance, bounds_proc) ⇒ TypeVariableModule
: (T::Module context, Type type, Symbol variance, (^-> Hash[Symbol, untyped])? bounds_proc) -> void
137 138 139 140 141 142 143 144 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 137 def initialize(context, type, variance, bounds_proc) @context = context @type = type @variance = variance @bounds_proc = bounds_proc || DEFAULT_BOUNDS_PROC super() end |
Instance Attribute Details
#type ⇒ Object (readonly)
: Type
134 135 136 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 134 def type @type end |
Instance Method Details
#coerce_to_type_variable ⇒ Object
: -> Tapioca::TypeVariable
173 174 175 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 173 def coerce_to_type_variable TypeVariable.new(name, @variance) end |
#fixed? ⇒ Boolean
: -> bool
153 154 155 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 153 def fixed? bounds.key?(:fixed) end |
#name ⇒ Object
: -> String?
147 148 149 150 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 147 def name constant_name = super constant_name&.split("::")&.last end |
#serialize ⇒ Object
: -> String
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/tapioca/sorbet_ext/generic_name_patch.rb', line 158 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 |