Class: Puppeteer::EventCallbackable::EventListeners
- Inherits:
-
Object
- Object
- Puppeteer::EventCallbackable::EventListeners
- Includes:
- Enumerable
- Defined in:
- lib/puppeteer/event_callbackable.rb
Instance Method Summary collapse
-
#add(&block) ⇒ String
Listener ID.
- #delete(id) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ EventListeners
constructor
A new instance of EventListeners.
Constructor Details
#initialize ⇒ EventListeners
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.
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
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 |