Class: Fire::State

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

Overview

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

Fire 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/fire/state.rb', line 11

def initialize(&procedure)
  @procedure = procedure
end

Instance Method Details

#&(other) ⇒ Object

set and



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

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

#callObject



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

def call
  set @procedure.call
end

#set(value) ⇒ Object (private)



32
33
34
35
36
37
38
39
40
41
# File 'lib/fire/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/fire/state.rb', line 20

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