Class: Rulebow::Fact
- Inherits:
-
Object
- Object
- Rulebow::Fact
- Defined in:
- lib/rulebow/fact.rb
Overview
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 `|`.
Direct Known Subclasses
Instance Method Summary collapse
-
#&(other) ⇒ Object
set and.
- #call(digest) ⇒ Object
-
#initialize(&procedure) ⇒ Fact
constructor
A new instance of Fact.
- #set(value) ⇒ Object private
-
#|(other) ⇒ Object
set or.
Constructor Details
#initialize(&procedure) ⇒ Fact
12 13 14 |
# File 'lib/rulebow/fact.rb', line 12 def initialize(&procedure) @procedure = procedure end |
Instance Method Details
#&(other) ⇒ Object
set and
27 28 29 |
# File 'lib/rulebow/fact.rb', line 27 def &(other) Fact.new{ |d| set(self.call(d)) & set(other.call(d)) } end |
#call(digest) ⇒ Object
17 18 19 |
# File 'lib/rulebow/fact.rb', line 17 def call(digest) set @procedure.call(digest) end |
#set(value) ⇒ Object (private)
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rulebow/fact.rb', line 34 def set(value) case value when Array value.compact when Boolean value ? true : [] else [value] end end |
#|(other) ⇒ Object
set or
22 23 24 |
# File 'lib/rulebow/fact.rb', line 22 def |(other) Fact.new{ |d| set(self.call(d)) | set(other.call(d)) } end |