Class: Kanal::Core::Helpers::Queue

Inherits:
Object
  • Object
show all
Includes:
Kanal::Core::Hooks
Defined in:
lib/kanal/core/helpers/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueue

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

#hooksObject (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

#dequeueObject



24
25
26
# File 'lib/kanal/core/helpers/queue.rb', line 24

def dequeue
  @items.shift
end

#empty?Boolean

Returns:

  • (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