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 =
%i[in out invariant].freeze
Instance Attribute Summary collapse
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
- #build_type ⇒ Object
-
#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, #error_message_for_obj_recursive, #hash, method_added, #recursively_valid?, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(variance) ⇒ TypeVariable
Returns a new instance of TypeVariable.
12 13 14 15 16 17 18 19 20 |
# File 'lib/types/types/type_variable.rb', line 12 def initialize(variance) case variance when Hash then raise ArgumentError.new("Pass bounds using a block. Got: #{variance}") when *VALID_VARIANCES then nil else 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
#build_type ⇒ Object
22 23 24 |
# File 'lib/types/types/type_variable.rb', line 22 def build_type nil end |
#name ⇒ Object
34 35 36 |
# File 'lib/types/types/type_variable.rb', line 34 def name Untyped.new.name end |
#subtype_of_single?(type) ⇒ Boolean
30 31 32 |
# File 'lib/types/types/type_variable.rb', line 30 def subtype_of_single?(type) true end |
#valid?(obj) ⇒ Boolean
26 27 28 |
# File 'lib/types/types/type_variable.rb', line 26 def valid?(obj) true end |