Class: Rigor::Trinary
- Inherits:
-
Object
- Object
- Rigor::Trinary
- Defined in:
- lib/rigor/trinary.rb
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
Class Attribute Summary collapse
-
.maybe ⇒ Object
readonly
Returns the value of attribute maybe.
-
.no ⇒ Object
readonly
Returns the value of attribute no.
-
.yes ⇒ Object
readonly
Returns the value of attribute yes.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#and(other) ⇒ Object
Conjunction.
- #hash ⇒ Object
-
#initialize(value) ⇒ Trinary
constructor
A new instance of Trinary.
- #inspect ⇒ Object
- #maybe? ⇒ Boolean
- #negate ⇒ Object
- #no? ⇒ Boolean
-
#or(other) ⇒ Object
Disjunction.
- #to_s ⇒ Object
- #yes? ⇒ Boolean
Constructor Details
Class Attribute Details
.maybe ⇒ Object (readonly)
Returns the value of attribute maybe.
22 23 24 |
# File 'lib/rigor/trinary.rb', line 22 def maybe @maybe end |
.no ⇒ Object (readonly)
Returns the value of attribute no.
22 23 24 |
# File 'lib/rigor/trinary.rb', line 22 def no @no end |
.yes ⇒ Object (readonly)
Returns the value of attribute yes.
22 23 24 |
# File 'lib/rigor/trinary.rb', line 22 def yes @yes end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
35 36 37 |
# File 'lib/rigor/trinary.rb', line 35 def value @value end |
Class Method Details
.from_symbol(symbol) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rigor/trinary.rb', line 24 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) ⇒ Object Also known as: eql?
81 82 83 |
# File 'lib/rigor/trinary.rb', line 81 def ==(other) other.is_a?(Trinary) && value == other.value end |
#and(other) ⇒ Object
Conjunction. yes & yes = yes, no with anything = no, otherwise maybe.
64 65 66 67 68 69 70 |
# File 'lib/rigor/trinary.rb', line 64 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 ⇒ Object
86 87 88 |
# File 'lib/rigor/trinary.rb', line 86 def hash value.hash end |
#inspect ⇒ Object
94 95 96 |
# File 'lib/rigor/trinary.rb', line 94 def inspect "#<Rigor::Trinary #{value}>" end |
#maybe? ⇒ Boolean
51 52 53 |
# File 'lib/rigor/trinary.rb', line 51 def maybe? value == :maybe end |
#negate ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rigor/trinary.rb', line 55 def negate case value when :yes then self.class.no when :no then self.class.yes else self.class.maybe end end |
#no? ⇒ Boolean
47 48 49 |
# File 'lib/rigor/trinary.rb', line 47 def no? value == :no end |
#or(other) ⇒ Object
Disjunction. yes with anything = yes, no & no = no, otherwise maybe.
73 74 75 76 77 78 79 |
# File 'lib/rigor/trinary.rb', line 73 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 ⇒ Object
90 91 92 |
# File 'lib/rigor/trinary.rb', line 90 def to_s value.to_s end |
#yes? ⇒ Boolean
43 44 45 |
# File 'lib/rigor/trinary.rb', line 43 def yes? value == :yes end |