Module: Plum::EventEmitter

Included in:
Connection, Stream
Defined in:
lib/plum/event_emitter.rb

Instance Method Summary collapse

Instance Method Details

#callback(name, *args) ⇒ Object

Invokes an event and call handlers with args.

Parameters:

  • name (Symbol)

    The identifier of event.


13
14
15
# File 'lib/plum/event_emitter.rb', line 13

def callback(name, *args)
  (cbs = callbacks[name]) && cbs.each {|cb| cb.call(*args) }
end

#on(name) { ... } ⇒ Object

Registers an event handler to specified event. An event can have multiple handlers.

Parameters:

  • name (Symbol)

    The name of event.

Yields:

  • Gives event-specific parameters.


7
8
9
# File 'lib/plum/event_emitter.rb', line 7

def on(name, &blk)
  (callbacks[name] ||= []) << blk
end