Class: Wongi::Engine::AlphaMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/wongi-engine/alpha_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, rete = nil) ⇒ AlphaMemory

Returns a new instance of AlphaMemory.



7
8
9
10
11
12
13
# File 'lib/wongi-engine/alpha_memory.rb', line 7

def initialize template, rete = nil
  @template = template
  @rete = rete
  @betas = []
  @wmes = []
  @frozen = false
end

Instance Attribute Details

#betasObject (readonly)

Returns the value of attribute betas.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def betas
  @betas
end

#reteObject (readonly)

Returns the value of attribute rete.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def rete
  @rete
end

#templateObject (readonly)

Returns the value of attribute template.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def template
  @template
end

#wmesObject (readonly)

Returns the value of attribute wmes.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def wmes
  @wmes
end

Instance Method Details

#activate(wme) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/wongi-engine/alpha_memory.rb', line 15

def activate wme
  betas.each do |beta|
    beta.right_activate wme
  end
  @wmes << wme
  wme.alphas << self
end

#inspectObject



36
37
38
# File 'lib/wongi-engine/alpha_memory.rb', line 36

def inspect
  "<Alpha #{__id__} template=#{template} wmes=#{wmes}>"
end

#remove(wme) ⇒ Object



23
24
25
26
27
28
# File 'lib/wongi-engine/alpha_memory.rb', line 23

def remove wme
  @wmes.delete wme
  # we don't need to unlink ourselves from the wme
  # because this is only called from WME#destroy
  # so the wme will take care of it itself
end

#snapshot!(alpha) ⇒ Object



30
31
32
33
34
# File 'lib/wongi-engine/alpha_memory.rb', line 30

def snapshot! alpha
  alpha.wmes.map( &:dup ).each do |wme|
    activate wme
  end
end

#to_sObject



40
41
42
# File 'lib/wongi-engine/alpha_memory.rb', line 40

def to_s
  inspect
end