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
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
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
37 38 39 |
# File 'lib/rigor/trinary.rb', line 37 def value @value end |
Class Method Details
.from_symbol(symbol) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rigor/trinary.rb', line 26 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 |
.maybe ⇒ Object
22 23 24 |
# File 'lib/rigor/trinary.rb', line 22 def maybe @maybe ||= new(:maybe).freeze end |
.no ⇒ Object
18 19 20 |
# File 'lib/rigor/trinary.rb', line 18 def no @no ||= new(:no).freeze end |
.yes ⇒ Object
14 15 16 |
# File 'lib/rigor/trinary.rb', line 14 def yes @yes ||= new(:yes).freeze end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
83 84 85 |
# File 'lib/rigor/trinary.rb', line 83 def ==(other) other.is_a?(Trinary) && value == other.value end |
#and(other) ⇒ Object
Conjunction. yes & yes = yes, no with anything = no, otherwise maybe.
66 67 68 69 70 71 72 |
# File 'lib/rigor/trinary.rb', line 66 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
88 89 90 |
# File 'lib/rigor/trinary.rb', line 88 def hash value.hash end |
#inspect ⇒ Object
96 97 98 |
# File 'lib/rigor/trinary.rb', line 96 def inspect "#<Rigor::Trinary #{value}>" end |
#maybe? ⇒ Boolean
53 54 55 |
# File 'lib/rigor/trinary.rb', line 53 def maybe? value == :maybe end |
#negate ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/rigor/trinary.rb', line 57 def negate case value when :yes then self.class.no when :no then self.class.yes when :maybe then self.class.maybe end end |
#no? ⇒ Boolean
49 50 51 |
# File 'lib/rigor/trinary.rb', line 49 def no? value == :no end |
#or(other) ⇒ Object
Disjunction. yes with anything = yes, no & no = no, otherwise maybe.
75 76 77 78 79 80 81 |
# File 'lib/rigor/trinary.rb', line 75 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
92 93 94 |
# File 'lib/rigor/trinary.rb', line 92 def to_s value.to_s end |
#yes? ⇒ Boolean
45 46 47 |
# File 'lib/rigor/trinary.rb', line 45 def yes? value == :yes end |