module Plum::EventEmitter

Public Instance Methods

callback(name, *args) click to toggle source

Invokes an event and call handlers with args. @param name [Symbol] The identifier of event.

# File lib/plum/event_emitter.rb, line 13
def callback(name, *args)
  @callbacks&.[](name)&.each { |cb| cb.call(*args) }
end
on(name, &blk) click to toggle source

Registers an event handler to specified event. An event can have multiple handlers. @param name [Symbol] The name of event. @yield Gives event-specific parameters.

# File lib/plum/event_emitter.rb, line 6
def on(name, &blk)
  @callbacks ||= {}
  (@callbacks[name] ||= []) << blk
end