Class: Ergo::State

Inherits:
Object
  • Object
show all
Defined in:
lib/ergo/state.rb

Overview

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

Ergo 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

FileState

Instance Method Summary collapse

Constructor Details

#initialize(&procedure) ⇒ State

Returns a new instance of State.



11
12
13
# File 'lib/ergo/state.rb', line 11

def initialize(&procedure)
  @procedure = procedure
end

Instance Method Details

#&(other) ⇒ Object

set and



25
26
27
# File 'lib/ergo/state.rb', line 25

def &(other)
  State.new{ |d| set(self.call(d)) & set(other.call(d)) }
end

#call(digest) ⇒ Object



15
16
17
# File 'lib/ergo/state.rb', line 15

def call(digest)
  set @procedure.call(digest)
end

#set(value) ⇒ Object (private)



32
33
34
35
36
37
38
39
40
41
# File 'lib/ergo/state.rb', line 32

def set(value)
  case value
  when Array
    value.compact
  when Boolean
    value ? true : []
  else
    [value]
  end
end

#|(other) ⇒ Object

set or



20
21
22
# File 'lib/ergo/state.rb', line 20

def |(other)
  State.new{ |d| set(self.call(d)) | set(other.call(d)) }
end