Class: Aikido::Zen::CappedMap Private
- Inherits:
-
Object
- Object
- Aikido::Zen::CappedMap
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/aikido/zen/capped_collections.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides a FIFO hash-like structure with a maximum size. Adding a new key after the capacity has been reached kicks the first element pair added out.
Direct Known Subclasses
Instance Attribute Summary collapse
- #capacity ⇒ Integer readonly private
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object private
-
#initialize(capacity) ⇒ CappedMap
constructor
private
A new instance of CappedMap.
Constructor Details
#initialize(capacity) ⇒ CappedMap
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CappedMap.
57 58 59 60 61 |
# File 'lib/aikido/zen/capped_collections.rb', line 57 def initialize(capacity) raise ArgumentError, "cannot set capacity lower than 1: #{capacity}" if capacity < 1 @capacity = capacity @data = {} end |
Instance Attribute Details
#capacity ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 |
# File 'lib/aikido/zen/capped_collections.rb', line 55 def capacity @capacity end |
Instance Method Details
#[]=(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 |
# File 'lib/aikido/zen/capped_collections.rb', line 63 def []=(key, value) @data[key] = value @data.delete(@data.each_key.first) if @data.size > @capacity end |