Class: T::Types::TypeVariable
- Defined in:
- lib/types/types/type_variable.rb
Overview
Since we do type erasure at runtime, this just validates the variance and provides some syntax for the static type checker
Direct Known Subclasses
Constant Summary collapse
- VALID_VARIANCES =
[:in, :out, :invariant]
Instance Attribute Summary collapse
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
-
#initialize(variance) ⇒ TypeVariable
constructor
A new instance of TypeVariable.
- #name ⇒ Object
- #subtype_of_single?(type) ⇒ Boolean
- #valid?(obj) ⇒ Boolean
Methods inherited from Base
#==, #describe_obj, #error_message_for_obj, #hash, method_added, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(variance) ⇒ TypeVariable
Returns a new instance of TypeVariable.
12 13 14 15 16 17 |
# File 'lib/types/types/type_variable.rb', line 12 def initialize(variance) if !VALID_VARIANCES.include?(variance) raise TypeError.new("invalid variance #{variance}") end @variance = variance end |
Instance Attribute Details
#variance ⇒ Object (readonly)
Returns the value of attribute variance.
8 9 10 |
# File 'lib/types/types/type_variable.rb', line 8 def variance @variance end |
Instance Method Details
#name ⇒ Object
27 28 29 |
# File 'lib/types/types/type_variable.rb', line 27 def name Untyped.new.name end |
#subtype_of_single?(type) ⇒ Boolean
23 24 25 |
# File 'lib/types/types/type_variable.rb', line 23 def subtype_of_single?(type) true end |
#valid?(obj) ⇒ Boolean
19 20 21 |
# File 'lib/types/types/type_variable.rb', line 19 def valid?(obj) true end |