0.0
No commit activity in last 3 years
No release in over 3 years
A gem for comparing boolean expressions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.13.1
~> 13.0
~> 0.1.18

Runtime

~> 0.8.1
 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