Class: Kanal::Core::Helpers::Queue
- Inherits:
-
Object
- Object
- Kanal::Core::Helpers::Queue
- Includes:
- Kanal::Core::Hooks
- Defined in:
- lib/kanal/core/helpers/queue.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
Instance Method Summary collapse
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(element) ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #remove(element) ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
13 14 15 16 17 |
# File 'lib/kanal/core/helpers/queue.rb', line 13 def initialize @items = [] @hooks = HookStorage.new hooks.register(:item_queued) # args arguments: item end |
Instance Attribute Details
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
11 12 13 |
# File 'lib/kanal/core/helpers/queue.rb', line 11 def hooks @hooks end |
Instance Method Details
#dequeue ⇒ Object
24 25 26 |
# File 'lib/kanal/core/helpers/queue.rb', line 24 def dequeue @items.shift end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/kanal/core/helpers/queue.rb', line 28 def empty? @items.empty? end |
#enqueue(element) ⇒ Object
19 20 21 22 |
# File 'lib/kanal/core/helpers/queue.rb', line 19 def enqueue(element) @items.append element @hooks.call :item_queued, element end |
#remove(element) ⇒ Object
32 33 34 |
# File 'lib/kanal/core/helpers/queue.rb', line 32 def remove(element) @items.delete(element) end |