class RBS::VarianceCalculator::Result
Result contains the set of type variables and itβs variance in a occurrence.
# Enumerates recorded type variables result.each do |name, variance| # name is the name of a type variable # variance is one of :unused | :covariant | :contravariant | :invariant end
You can test with compatible? method if the type variable occurrences are compatible with specified (annotated) variance.
# When T is declared as `out T` result.compatible?(:T, with_annotation: :covariant) # When T is declared as `in T` result.compatible?(:T, with_annotation: :contravariant) # When T is declared as `T` result.compatible?(:T, with_annotation: :invariant)
Attributes
result
[R]
Hash[Symbol, variance]
Public Class Methods
Public Instance Methods
(Symbol, with_annotation: variance) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 45 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
(Symbol) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 24 def contravariant(x) case result[x] when :unused result[x] = :contravariant when :covariant result[x] = :invariant end end
(Symbol) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 15 def covariant(x) case result[x] when :unused result[x] = :covariant when :contravariant result[x] = :invariant end end
() { ([ Symbol, variance ]) → void } → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 37 def each(&block) result.each(&block) end
(Symbol) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 41 def include?(name) result.key?(name) end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 60 def incompatible?(params) # @type set: Hash[Symbol] set = Set[] params.each do |param| unless compatible?(param.name, with_annotation: param.variance) set << param.name end end unless set.empty? set end end
(Symbol) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/variance_calculator.rb, line 33 def invariant(x) result[x] = :invariant end