Class: Quonfig::FixedSizeHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/quonfig/fixed_size_hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_size) ⇒ FixedSizeHash

Returns a new instance of FixedSizeHash.



5
6
7
8
# File 'lib/quonfig/fixed_size_hash.rb', line 5

def initialize(max_size)
  @max_size = max_size
  super()
end

Instance Method Details

#[]=(key, value) ⇒ Object



10
11
12
13
# File 'lib/quonfig/fixed_size_hash.rb', line 10

def []=(key, value)
  shift if size >= @max_size && !key?(key) # Only evict if adding a new key
  super
end