Class: Luogu::HistoryQueue
- Inherits:
-
Object
- Object
- Luogu::HistoryQueue
- Defined in:
- lib/luogu/history_queue.rb
Instance Method Summary collapse
- #dequeue ⇒ Object
- #enqueue(element) ⇒ Object
-
#initialize(max_size = 12) ⇒ HistoryQueue
constructor
A new instance of HistoryQueue.
- #size ⇒ Object
- #to_a ⇒ Object
- #to_json ⇒ Object
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
#dequeue ⇒ Object
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 |
#size ⇒ Object
19 20 21 |
# File 'lib/luogu/history_queue.rb', line 19 def size @queue.size end |
#to_a ⇒ Object
23 24 25 |
# File 'lib/luogu/history_queue.rb', line 23 def to_a @queue end |
#to_json ⇒ Object
27 28 29 |
# File 'lib/luogu/history_queue.rb', line 27 def to_json JSON.pretty_generate @queue end |