0.0
The project is in a healthy, maintained state
A gem for comparing boolean expressions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
 Project Readme

Table of Truth

A gem for comparing boolean expressions.

Usage

Create a table:

# Require the gem
require 'table_of_truth'

table = TableOfTruth.new do
  # Define inputs
  input :something_enabled?
  input :result_of_expensive_call?

  # Define an expression
  expression 'early check' do
    if result_of_expensive_call?
      something_enabled?
    else
      true
    end
  end

  # Define another expression
  expression 'late check' do
    next false if !something_enabled? && result_of_expensive_call?

    true
  end
end

then, print the table:

table.print! # outputs the following:
# something_enabled? | expensive_call_to_service? || early check | late check
#         ✗          |             ✗              ||      ✔      |     ✔
#         ✗          |             ✔              ||      ✗      |     ✗
#         ✔          |             ✗              ||      ✔      |     ✔
#         ✔          |             ✔              ||      ✔      |     ✔

or, check equivalency:

table.equivalent? #=> true if all expressions are equal for all input combinations