Class: RBS::VarianceCalculator::Result
- Inherits:
-
Object
- Object
- RBS::VarianceCalculator::Result
- Defined in:
- lib/rbs/variance_calculator.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #compatible?(var, with_annotation:) ⇒ Boolean
- #contravariant(x) ⇒ Object
- #covariant(x) ⇒ Object
- #each(&block) ⇒ Object
- #include?(name) ⇒ Boolean
- #incompatible?(params) ⇒ Boolean
-
#initialize(variables:) ⇒ Result
constructor
A new instance of Result.
- #invariant(x) ⇒ Object
Constructor Details
#initialize(variables:) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 |
# File 'lib/rbs/variance_calculator.rb', line 8 def initialize(variables:) @result = {} variables.each do |x| result[x] = :unused end end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/rbs/variance_calculator.rb', line 6 def result @result end |
Instance Method Details
#compatible?(var, with_annotation:) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File '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 |
#contravariant(x) ⇒ Object
24 25 26 27 28 29 30 31 |
# File '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 |
#covariant(x) ⇒ Object
15 16 17 18 19 20 21 22 |
# File '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 |
#each(&block) ⇒ Object
37 38 39 |
# File 'lib/rbs/variance_calculator.rb', line 37 def each(&block) result.each(&block) end |
#include?(name) ⇒ Boolean
41 42 43 |
# File 'lib/rbs/variance_calculator.rb', line 41 def include?(name) result.key?(name) end |
#incompatible?(params) ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File '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 |
#invariant(x) ⇒ Object
33 34 35 |
# File 'lib/rbs/variance_calculator.rb', line 33 def invariant(x) result[x] = :invariant end |