Module: Plum::EventEmitter
- Included in:
- Connection, Stream
- Defined in:
- lib/plum/event_emitter.rb
Instance Method Summary collapse
-
#callback(name, *args) ⇒ Object
Invokes an event and call handlers with args.
-
#on(name) { ... } ⇒ Object
Registers an event handler to specified event.
Instance Method Details
#callback(name, *args) ⇒ Object
Invokes an event and call handlers with args.
14 15 16 |
# File 'lib/plum/event_emitter.rb', line 14 def callback(name, *args) @callbacks&.[](name)&.each { |cb| cb.call(*args) } end |
#on(name) { ... } ⇒ Object
Registers an event handler to specified event. An event can have multiple handlers.
7 8 9 10 |
# File 'lib/plum/event_emitter.rb', line 7 def on(name, &blk) @callbacks ||= {} (@callbacks[name] ||= []) << blk end |