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 =
%i[in out invariant].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#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



30
31
32
# File 'lib/types/types/type_variable.rb', line 30

def name
  Untyped.new.name
end

#subtype_of_single?(type) ⇒ Boolean

Returns:



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

def subtype_of_single?(type)
  true
end

#valid?(obj) ⇒ Boolean

Returns:



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

def valid?(obj)
  true
end