Class: Wongi::Engine::AlphaMemory
- Inherits:
-
Object
- Object
- Wongi::Engine::AlphaMemory
- Defined in:
- lib/wongi-engine/alpha_memory.rb
Instance Attribute Summary collapse
-
#betas ⇒ Object
readonly
Returns the value of attribute betas.
-
#rete ⇒ Object
readonly
Returns the value of attribute rete.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #activate(wme) ⇒ Object
-
#initialize(template, rete = nil) ⇒ AlphaMemory
constructor
A new instance of AlphaMemory.
- #inspect ⇒ Object
- #remove(wme) ⇒ Object
- #snapshot!(alpha) ⇒ Object
- #to_s ⇒ Object
- #wmes ⇒ Object
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
#betas ⇒ Object (readonly)
Returns the value of attribute betas.
5 6 7 |
# File 'lib/wongi-engine/alpha_memory.rb', line 5 def betas @betas end |
#rete ⇒ Object (readonly)
Returns the value of attribute rete.
5 6 7 |
# File 'lib/wongi-engine/alpha_memory.rb', line 5 def rete @rete end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/wongi-engine/alpha_memory.rb', line 5 def template @template 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.alpha_activate wme end @wmes << wme wme.alphas << self end |
#inspect ⇒ Object
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_s ⇒ Object
40 41 42 |
# File 'lib/wongi-engine/alpha_memory.rb', line 40 def to_s inspect end |
#wmes ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/wongi-engine/alpha_memory.rb', line 44 def wmes Enumerator.new do |y| @wmes.dup.each do |wme| y << wme unless wme.deleted? end end end |