Class: Luogu::HistoryQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/luogu/history_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 12) ⇒ HistoryQueue

Returns a new instance of HistoryQueue.



3
4
5
6
# File 'lib/luogu/history_queue.rb', line 3

def initialize(max_size = 12)
  @queue = []
  @max_size = max_size
end

Instance Method Details

#dequeueObject



15
16
17
# File 'lib/luogu/history_queue.rb', line 15

def dequeue
  @queue.shift
end

#enqueue(element) ⇒ Object



8
9
10
11
12
13
# File 'lib/luogu/history_queue.rb', line 8

def enqueue(element)
  if @queue.size == @max_size
    @queue.shift
  end
  @queue << element
end

#sizeObject



19
20
21
# File 'lib/luogu/history_queue.rb', line 19

def size
  @queue.size
end

#to_aObject



23
24
25
# File 'lib/luogu/history_queue.rb', line 23

def to_a
  @queue
end

#to_jsonObject



27
28
29
# File 'lib/luogu/history_queue.rb', line 27

def to_json
  JSON.pretty_generate @queue
end