Class: KBS::WorkingMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/kbs/working_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorkingMemory

Returns a new instance of WorkingMemory.



7
8
9
10
# File 'lib/kbs/working_memory.rb', line 7

def initialize
  @facts = []
  @observers = []
end

Instance Attribute Details

#factsObject (readonly)

Returns the value of attribute facts.



5
6
7
# File 'lib/kbs/working_memory.rb', line 5

def facts
  @facts
end

Instance Method Details

#add_fact(fact) ⇒ Object



12
13
14
15
16
# File 'lib/kbs/working_memory.rb', line 12

def add_fact(fact)
  @facts << fact
  notify_observers(:add, fact)
  fact
end

#add_observer(observer) ⇒ Object



24
25
26
# File 'lib/kbs/working_memory.rb', line 24

def add_observer(observer)
  @observers << observer
end

#notify_observers(action, fact) ⇒ Object



28
29
30
# File 'lib/kbs/working_memory.rb', line 28

def notify_observers(action, fact)
  @observers.each { |obs| obs.update(action, fact) }
end

#remove_fact(fact) ⇒ Object



18
19
20
21
22
# File 'lib/kbs/working_memory.rb', line 18

def remove_fact(fact)
  @facts.delete(fact)
  notify_observers(:remove, fact)
  fact
end