123456789_123456789_123456789_123456789_123456789_

Class: RBS::VarianceCalculator::Result

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/variance_calculator.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(variables:) ⇒ Result

[ GitHub ]

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

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

Instance Attribute Details

#result (readonly)

[ GitHub ]

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

attr_reader :result

Instance Method Details

#compatible?(var, with_annotation:) ⇒ Boolean

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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)

[ GitHub ]

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

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

#include?(name) ⇒ Boolean

[ GitHub ]

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

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

#invariant(x)

[ GitHub ]

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

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