Class: Memory
- Inherits:
-
Object
- Object
- Memory
- Defined in:
- lib/sheldon/memory.rb
Instance Method Summary collapse
- #add(recall_cue, hash) ⇒ Object
- #forget(recall_cue) ⇒ Object
- #has_cue?(recall_cue) ⇒ Boolean
-
#initialize(brain_location) ⇒ Memory
constructor
A new instance of Memory.
- #list_cues ⇒ Object
- #recall(recall_cue) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(brain_location) ⇒ Memory
Returns a new instance of Memory.
5 6 7 8 |
# File 'lib/sheldon/memory.rb', line 5 def initialize(brain_location) database_path = File.join(brain_location, "db.yml") @database = YAML::Store.new(database_path) end |
Instance Method Details
#add(recall_cue, hash) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/sheldon/memory.rb', line 10 def add(recall_cue, hash) raise "cue already used" if has_cue?(recall_cue) @database.transaction do @database[recall_cue] = hash end end |
#forget(recall_cue) ⇒ Object
22 23 24 25 |
# File 'lib/sheldon/memory.rb', line 22 def forget(recall_cue) raise "no entry for cue" unless has_cue?(recall_cue) @database.transaction{ @database.delete(recall_cue) } end |
#has_cue?(recall_cue) ⇒ Boolean
35 36 37 |
# File 'lib/sheldon/memory.rb', line 35 def has_cue?(recall_cue) list_cues.any?{ |cue| cue == recall_cue } end |
#list_cues ⇒ Object
31 32 33 |
# File 'lib/sheldon/memory.rb', line 31 def list_cues @database.transaction { @database.roots } end |
#recall(recall_cue) ⇒ Object
17 18 19 20 |
# File 'lib/sheldon/memory.rb', line 17 def recall(recall_cue) raise "no entry for cue" unless has_cue?(recall_cue) @database.transaction { @database[recall_cue] } end |
#size ⇒ Object
27 28 29 |
# File 'lib/sheldon/memory.rb', line 27 def size list_cues.size end |