Class: RBS::VarianceCalculator::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/variance_calculator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variables:) ⇒ Result

Returns a new instance of Result.



6
7
8
9
10
11
# File 'lib/rbs/variance_calculator.rb', line 6

def initialize(variables:)
  @result = {}
  variables.each do |x|
    result[x] = :unused
  end
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/rbs/variance_calculator.rb', line 4

def result
  @result
end

Instance Method Details

#compatible?(var, with_annotation:) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rbs/variance_calculator.rb', line 43

def compatible?(var, with_annotation:)
  variance = result[var]

  case
  when variance == :unused
    true
  when with_annotation == :invariant
    true
  when variance == with_annotation
    true
  else
    false
  end
end

#contravariant(x) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rbs/variance_calculator.rb', line 22

def contravariant(x)
  case result[x]
  when :unused
    result[x] = :contravariant
  when :covariant
    result[x] = :invariant
  end
end

#covariant(x) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rbs/variance_calculator.rb', line 13

def covariant(x)
  case result[x]
  when :unused
    result[x] = :covariant
  when :contravariant
    result[x] = :invariant
  end
end

#each(&block) ⇒ Object



35
36
37
# File 'lib/rbs/variance_calculator.rb', line 35

def each(&block)
  result.each(&block)
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/rbs/variance_calculator.rb', line 39

def include?(name)
  result.key?(name)
end

#invariant(x) ⇒ Object



31
32
33
# File 'lib/rbs/variance_calculator.rb', line 31

def invariant(x)
  result[x] = :invariant
end