Class: T::Types::TypeVariable

Inherits:
Base
  • Object
show all
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

TypeMember, TypeTemplate

Constant Summary collapse

VALID_VARIANCES =
[:in, :out, :invariant]

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#varianceObject (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

#nameObject



27
28
29
# File 'lib/types/types/type_variable.rb', line 27

def name
  Untyped.new.name
end

#subtype_of_single?(type) ⇒ Boolean

Returns:



23
24
25
# File 'lib/types/types/type_variable.rb', line 23

def subtype_of_single?(type)
  true
end

#valid?(obj) ⇒ Boolean

Returns:



19
20
21
# File 'lib/types/types/type_variable.rb', line 19

def valid?(obj)
  true
end