class Rulebow::Fact

Rulebow’s logic system is a *set logic* system. That means an empty set, ‘[]` is treated as `false` and a non-empty set is `true`.

Rulebow handles complex logic by building-up lazy logic constructs. It’s logical operators are defined using single charcter symbols, e.g. ‘&` and `|`.

Public Class Methods

new(&procedure) click to toggle source
# File lib/rulebow/fact.rb, line 12
def initialize(&procedure)
  @procedure = procedure
end

Public Instance Methods

&(other) click to toggle source

set and

# File lib/rulebow/fact.rb, line 27
def &(other)
  Fact.new{ |d| set(self.call(d)) & set(other.call(d)) }
end
call(digest) click to toggle source
# File lib/rulebow/fact.rb, line 17
def call(digest)
  set @procedure.call(digest)
end
|(other) click to toggle source

set or

# File lib/rulebow/fact.rb, line 22
def |(other)
  Fact.new{ |d| set(self.call(d)) | set(other.call(d)) }
end

Private Instance Methods

set(value) click to toggle source
# File lib/rulebow/fact.rb, line 34
def set(value)
  case value
  when Array
    value.compact
  when Boolean
    value ? true : []
  else
    [value]
  end
end