Class: RotationHash
- Inherits:
-
Hash
- Object
- Hash
- RotationHash
- Defined in:
- lib/rotation_hash.rb
Overview
A Hash descendant with elements count limit and rotation
Constant Summary collapse
- VERSION =
Current library version
'0.1.0'
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Overloaded Hash assignment method.
-
#initialize(rotation_limit, *args) ⇒ RotationHash
constructor
Create a new RotationHash.
Constructor Details
#initialize(rotation_limit, *args) ⇒ RotationHash
Note:
The first argument used to set a limit all the others passed to the Hash as is.
Create a new RotationHash
25 26 27 28 |
# File 'lib/rotation_hash.rb', line 25 def initialize(rotation_limit, *args) @rotation_limit = rotation_limit super(*args) end |
Instance Method Details
#[]=(key, value) ⇒ Object
Overloaded Hash assignment method. Adds elements and on reaching the limit automatically rotates the Hash
37 38 39 40 |
# File 'lib/rotation_hash.rb', line 37 def []=(key, value) shift if length + 1 > @rotation_limit super(key, value) end |