ternary_logic

This library implements Ternary Logic for Ruby. Ternary logic (also known as 3-value-logic) adds the value “Unknown” to the two traditional (i.e. boolean) logic values, True and False. This is useful for adding a bit of fuzzyness into your logic.

To install:

sudo gem install visfleet-ternary_logic

To use:

require 'ternary_logic'

You now have the additional constant, UNKNOWN, to use alongside the constants true and false.

state = UNKNOWN
if state == UNKNWON
  puts "Don't know?"
end

You can use the logical operators “|” and “&” to compare UNKNOWN with true and false values.

state = (true | UNKNOWN)
state = (UNKNOWN & true)

Ternary logic uses the following truth table:

UNKNOWN & true == UNKNOWN
UNKNOWN & false == false
UNKNOWN & UNKNOWN == UNKNOWN

UNKNOWN | true == true
UNKNOWN | false == UNKNOWN
UNKNOWN | UNKNOWN == UNKNOWN

Copyright © 2009 VisFleet. See LICENSE for details.