Class: Aikido::Zen::CappedSet Private
- Inherits:
-
Object
- Object
- Aikido::Zen::CappedSet
- 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 set with a maximum size. Adding an element after the capacity has been reached kicks the oldest element in the set out, while maintaining the uniqueness property of a set (relying on #eql? and #hash).
Direct Known Subclasses
Instance Attribute Summary collapse
- #capacity ⇒ Integer readonly private
Instance Method Summary collapse
- #<<(element) ⇒ Object (also: #add, #push) private
- #as_json ⇒ Object private
- #each(&b) ⇒ Object private
-
#initialize(capacity) ⇒ CappedSet
constructor
private
A new instance of CappedSet.
Constructor Details
#initialize(capacity) ⇒ CappedSet
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 CappedSet.
21 22 23 |
# File 'lib/aikido/zen/capped_collections.rb', line 21 def initialize(capacity) @data = CappedMap.new(capacity) 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.
19 20 21 |
# File 'lib/aikido/zen/capped_collections.rb', line 19 def capacity @capacity end |
Instance Method Details
#<<(element) ⇒ Object Also known as: add, push
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.
25 26 27 28 |
# File 'lib/aikido/zen/capped_collections.rb', line 25 def <<(element) @data[element] = nil self end |
#as_json ⇒ 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.
36 37 38 |
# File 'lib/aikido/zen/capped_collections.rb', line 36 def as_json map(&:as_json) end |
#each(&b) ⇒ 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.
32 33 34 |
# File 'lib/aikido/zen/capped_collections.rb', line 32 def each(&b) @data.each_key(&b) end |