Class: Rigor::Trinary
- Inherits:
-
Object
- Object
- Rigor::Trinary
- Defined in:
- lib/rigor/trinary.rb,
sig/rigor/trinary.rbs
Overview
Three-valued logic value object shared by capability queries, relational queries, and any analyzer surface that distinguishes "proven yes", "proven no", and "cannot prove either".
See docs/type-specification/relations-and-certainty.md for semantics and docs/internal-spec/internal-type-api.md for the contract.
Constant Summary collapse
- VALUES =
%i[yes no maybe].freeze
- YES =
- NO =
- MAYBE =
Class Attribute Summary collapse
-
.maybe ⇒ Trinary
readonly
Returns the value of attribute maybe.
-
.no ⇒ Trinary
readonly
Returns the value of attribute no.
-
.yes ⇒ Trinary
readonly
Returns the value of attribute yes.
Instance Attribute Summary collapse
-
#value ⇒ value
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
-
#and(other) ⇒ Trinary
Conjunction.
- #hash ⇒ Integer
-
#initialize(value) ⇒ Trinary
constructor
A new instance of Trinary.
- #inspect ⇒ String
- #maybe? ⇒ Boolean
- #negate ⇒ Trinary
- #no? ⇒ Boolean
-
#or(other) ⇒ Trinary
Disjunction.
- #to_s ⇒ String
- #yes? ⇒ Boolean
Constructor Details
Class Attribute Details
.maybe ⇒ Trinary (readonly)
Returns the value of attribute maybe.
18 19 20 |
# File 'lib/rigor/trinary.rb', line 18 def maybe @maybe end |
.no ⇒ Trinary (readonly)
Returns the value of attribute no.
18 19 20 |
# File 'lib/rigor/trinary.rb', line 18 def no @no end |
.yes ⇒ Trinary (readonly)
Returns the value of attribute yes.
18 19 20 |
# File 'lib/rigor/trinary.rb', line 18 def yes @yes end |
Instance Attribute Details
#value ⇒ value (readonly)
Returns the value of attribute value.
31 32 33 |
# File 'lib/rigor/trinary.rb', line 31 def value @value end |
Class Method Details
.from_symbol(symbol) ⇒ Trinary
20 21 22 23 24 25 26 27 28 |
# File 'lib/rigor/trinary.rb', line 20 def from_symbol(symbol) case symbol when :yes then yes when :no then no when :maybe then maybe else raise ArgumentError, "unknown trinary value: #{symbol.inspect}" end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
77 78 79 |
# File 'lib/rigor/trinary.rb', line 77 def ==(other) other.is_a?(Trinary) && value == other.value end |
#and(other) ⇒ Trinary
Conjunction. yes & yes = yes, no with anything = no, otherwise maybe.
60 61 62 63 64 65 66 |
# File 'lib/rigor/trinary.rb', line 60 def and(other) coerced = coerce(other) return self.class.no if no? || coerced.no? return self.class.yes if yes? && coerced.yes? self.class.maybe end |
#hash ⇒ Integer
82 83 84 |
# File 'lib/rigor/trinary.rb', line 82 def hash value.hash end |
#inspect ⇒ String
90 91 92 |
# File 'lib/rigor/trinary.rb', line 90 def inspect "#<Rigor::Trinary #{value}>" end |
#maybe? ⇒ Boolean
47 48 49 |
# File 'lib/rigor/trinary.rb', line 47 def maybe? value == :maybe end |
#negate ⇒ Trinary
51 52 53 54 55 56 57 |
# File 'lib/rigor/trinary.rb', line 51 def negate case value when :yes then self.class.no when :no then self.class.yes else self.class.maybe end end |
#no? ⇒ Boolean
43 44 45 |
# File 'lib/rigor/trinary.rb', line 43 def no? value == :no end |
#or(other) ⇒ Trinary
Disjunction. yes with anything = yes, no & no = no, otherwise maybe.
69 70 71 72 73 74 75 |
# File 'lib/rigor/trinary.rb', line 69 def or(other) coerced = coerce(other) return self.class.yes if yes? || coerced.yes? return self.class.no if no? && coerced.no? self.class.maybe end |
#to_s ⇒ String
86 87 88 |
# File 'lib/rigor/trinary.rb', line 86 def to_s value.to_s end |
#yes? ⇒ Boolean
39 40 41 |
# File 'lib/rigor/trinary.rb', line 39 def yes? value == :yes end |