Class: Console::Mux::RollingArray
- Defined in:
- lib/console/mux/rolling_array.rb
Overview
Array that limits itself to some fixed size. Newly added elements kick out the oldest element when at the limit.
Instance Attribute Summary collapse
-
#maxsize ⇒ Object
Returns the value of attribute maxsize.
Instance Method Summary collapse
-
#<<(other) ⇒ Object
Append an element to the array.
-
#initialize(maxsize) ⇒ RollingArray
constructor
A new instance of RollingArray.
Constructor Details
#initialize(maxsize) ⇒ RollingArray
Returns a new instance of RollingArray.
29 30 31 |
# File 'lib/console/mux/rolling_array.rb', line 29 def initialize(maxsize) @maxsize = maxsize end |
Instance Attribute Details
#maxsize ⇒ Object
Returns the value of attribute maxsize.
26 27 28 |
# File 'lib/console/mux/rolling_array.rb', line 26 def maxsize @maxsize end |
Instance Method Details
#<<(other) ⇒ Object
Append an element to the array. If the size of the array would overflow the maxsize, the array is shifted.
35 36 37 38 |
# File 'lib/console/mux/rolling_array.rb', line 35 def <<(other) super shift if size > maxsize end |