Class: Puppeteer::EventCallbackable::EventListeners

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/puppeteer/event_callbackable.rb

Instance Method Summary collapse

Constructor Details

#initializeEventListeners

Returns a new instance of EventListeners.



7
8
9
# File 'lib/puppeteer/event_callbackable.rb', line 7

def initialize
  @listeners = {}
end

Instance Method Details

#add(&block) ⇒ String

Returns Listener ID.

Returns:

  • (String)

    Listener ID



12
13
14
15
16
# File 'lib/puppeteer/event_callbackable.rb', line 12

def add(&block)
  id = SecureRandom.hex(8)
  @listeners[id] = block
  id
end

#delete(id) ⇒ Object

Parameters:

  • id (String)

    Listener ID returned on #add



19
20
21
# File 'lib/puppeteer/event_callbackable.rb', line 19

def delete(id)
  @listeners.delete(id)
end

#each(&block) ⇒ Object



24
25
26
# File 'lib/puppeteer/event_callbackable.rb', line 24

def each(&block)
  @listeners.values.each(&block)
end