Class: InMemoryStorage
- Inherits:
-
Object
- Object
- InMemoryStorage
- Defined in:
- lib/inmemory_storage.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_to_list(key, object) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
- #get_list(key) ⇒ Object
-
#initialize(name) ⇒ InMemoryStorage
constructor
A new instance of InMemoryStorage.
- #remove_from_list(key, object) ⇒ Object
- #set(key, object) ⇒ Object
Constructor Details
#initialize(name) ⇒ InMemoryStorage
Returns a new instance of InMemoryStorage.
19 20 21 22 |
# File 'lib/inmemory_storage.rb', line 19 def initialize(name) @name = name @keys = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/inmemory_storage.rb', line 17 def name @name end |
Instance Method Details
#add_to_list(key, object) ⇒ Object
40 41 42 43 |
# File 'lib/inmemory_storage.rb', line 40 def add_to_list(key, object) @keys[key] ||= [] @keys[key] << object end |
#clear ⇒ Object
49 50 51 |
# File 'lib/inmemory_storage.rb', line 49 def clear @keys = {} end |
#delete(key) ⇒ Object
32 33 34 |
# File 'lib/inmemory_storage.rb', line 32 def delete(key) @keys.delete key end |
#get(key) ⇒ Object
24 25 26 |
# File 'lib/inmemory_storage.rb', line 24 def get(key) @keys[key] end |
#get_list(key) ⇒ Object
36 37 38 |
# File 'lib/inmemory_storage.rb', line 36 def get_list(key) @keys[key] || [] end |
#remove_from_list(key, object) ⇒ Object
45 46 47 |
# File 'lib/inmemory_storage.rb', line 45 def remove_from_list(key, object) @keys.delete(object) end |
#set(key, object) ⇒ Object
28 29 30 |
# File 'lib/inmemory_storage.rb', line 28 def set(key, object) @keys[key] = object end |