Class: Infobar::FIFO

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/infobar/fifo.rb

Instance Method Summary collapse

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

#clearObject



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

Returns:

  • (Boolean)


28
29
30
# File 'lib/infobar/fifo.rb', line 28

def empty?
  @i.zero?
end

#max_sizeObject



9
10
11
# File 'lib/infobar/fifo.rb', line 9

def max_size
  @n
end