Class: FixedArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ignition/core/fixed_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(num = 50) ⇒ FixedArray

Returns a new instance of FixedArray.



4
5
6
7
# File 'lib/ignition/core/fixed_array.rb', line 4

def initialize(num = 50)
  @size = num
  @queue = Array.new
end

Instance Method Details

#<<(value) ⇒ Object



26
27
28
# File 'lib/ignition/core/fixed_array.rb', line 26

def <<(value)
  push(value)
end

#each(&blk) ⇒ Object



9
10
11
# File 'lib/ignition/core/fixed_array.rb', line 9

def each(&blk)
  @queue.each(&blk)
end

#popObject



13
14
15
# File 'lib/ignition/core/fixed_array.rb', line 13

def pop
  @queue.pop
end

#push(value) ⇒ Object



17
18
19
20
# File 'lib/ignition/core/fixed_array.rb', line 17

def push(value)
  @queue.shift if @queue.size >= @size
  @queue.push(value)
end

#to_aObject



22
23
24
# File 'lib/ignition/core/fixed_array.rb', line 22

def to_a
  @queue.to_a
end