Class: Infobar::FIFO
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(n) ⇒ FIFO
constructor
A new instance of FIFO.
- #max_size ⇒ Object
Constructor Details
#initialize(n) ⇒ FIFO
Returns a new instance of FIFO.
4 5 6 7 |
# File 'lib/infobar/fifo.rb', line 4 def initialize(n) @n = n clear end |
Instance Method Details
#<<(value) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/infobar/fifo.rb', line 13 def <<(value) @i += 1 if @i > @n @values.shift @i -= 1 end @values.push(value) self end |
#clear ⇒ Object
34 35 36 37 38 |
# File 'lib/infobar/fifo.rb', line 34 def clear @i = 0 @values = [] self end |
#each(&block) ⇒ Object
23 24 25 26 |
# File 'lib/infobar/fifo.rb', line 23 def each(&block) @values.each(&block) self end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/infobar/fifo.rb', line 28 def empty? @i.zero? end |
#max_size ⇒ Object
9 10 11 |
# File 'lib/infobar/fifo.rb', line 9 def max_size @n end |