Class: Factis::Memory
- Inherits:
-
Object
- Object
- Factis::Memory
- Defined in:
- lib/factis/memory.rb
Overview
This is the workhorse of Factis. It’s what does the actual tracking of facts.
Class Method Summary collapse
-
.all_facts ⇒ Hash
Get the entire facts hash.
-
.forget(fact) ⇒ Object
Removes the given fact (key) from internal storage.
-
.known_fact?(fact) ⇒ Boolean
Determines if the given fact key is already known.
-
.memorize(fact, content, options = {:overwrite => false}) ⇒ Object
Stores content as fact, optionally overwriting said content.
-
.recall(fact) ⇒ Object
Get fact content by key.
-
.reset! ⇒ Object
Clear the entire facts hash.
Class Method Details
.all_facts ⇒ Hash
Get the entire facts hash
24 25 26 27 |
# File 'lib/factis/memory.rb', line 24 def self.all_facts init_memory! @facts end |
.forget(fact) ⇒ Object
Removes the given fact (key) from internal storage
70 71 72 73 74 |
# File 'lib/factis/memory.rb', line 70 def self.forget(fact) init_memory! detect_unknown_fact(fact, 'Trying to forget an unknown fact') @facts.delete(fact) end |
.known_fact?(fact) ⇒ Boolean
Determines if the given fact key is already known
57 58 59 60 |
# File 'lib/factis/memory.rb', line 57 def self.known_fact?(fact) init_memory! @facts.keys.include?(fact) end |
.memorize(fact, content, options = {:overwrite => false}) ⇒ Object
Stores content as fact, optionally overwriting said content
41 42 43 44 45 46 47 48 49 |
# File 'lib/factis/memory.rb', line 41 def self.memorize(fact, content, = {:overwrite => false}) init_memory! if known_fact?(fact) unless [:overwrite] == true raise %{Cannot memorize a fact more than once: '#{fact}'} end end @facts[fact] = content end |
.recall(fact) ⇒ Object
Get fact content by key
84 85 86 87 88 |
# File 'lib/factis/memory.rb', line 84 def self.recall(fact) init_memory! detect_unknown_fact(fact, 'Trying to recall an unknown fact') @facts[fact] end |
.reset! ⇒ Object
Clear the entire facts hash
92 93 94 95 |
# File 'lib/factis/memory.rb', line 92 def self.reset! init_memory! @facts.clear end |