Class: SpeedGun::Store::Memory
- Defined in:
- lib/speed_gun/store/memory.rb
Constant Summary collapse
- DEFAULT_MAX_ENTRIES =
100
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, val) ⇒ Object
-
#initialize(options = {}) ⇒ Memory
constructor
A new instance of Memory.
Constructor Details
#initialize(options = {}) ⇒ Memory
Returns a new instance of Memory.
6 7 8 9 10 |
# File 'lib/speed_gun/store/memory.rb', line 6 def initialize( = {}) @max_entries = [:max_entries] || DEFAULT_MAX_ENTRIES @store = {} @stored_list = [] end |
Instance Method Details
#[](id) ⇒ Object
12 13 14 |
# File 'lib/speed_gun/store/memory.rb', line 12 def [](id) @store[id] end |
#[]=(id, val) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/speed_gun/store/memory.rb', line 16 def []=(id, val) @store[id] = val @stored_list.push(id) @store.delete(@stored_list.shift) while @stored_list.length > @max_entries end |