Class: Low::Support::PoolHash
- Inherits:
-
Hash
- Object
- Hash
- Low::Support::PoolHash
- Defined in:
- lib/support/pool_hash.rb
Instance Method Summary collapse
- #add(key, value) ⇒ Object
-
#initialize(max_size) ⇒ PoolHash
constructor
A new instance of PoolHash.
Constructor Details
#initialize(max_size) ⇒ PoolHash
Returns a new instance of PoolHash.
6 7 8 9 10 |
# File 'lib/support/pool_hash.rb', line 6 def initialize(max_size) @max_size = max_size super() end |
Instance Method Details
#add(key, value) ⇒ Object
12 13 14 15 16 |
# File 'lib/support/pool_hash.rb', line 12 def add(key, value) # Prune the hash when a new item added. shift if size >= @max_size && !key?(key) self[key] = value end |