class RbMinivents::Events

Public Class Methods

new() click to toggle source
# File lib/rbminivents.rb, line 4
def initialize
  @handlers = {}
end

Public Instance Methods

emit(name, *args) click to toggle source

Emit: send event, callbacks will be triggered

# File lib/rbminivents.rb, line 22
 def emit(name, *args)
  @handlers[name] ||= []
  @handlers[name].each { |handler| handler.call(*args) }
end
off(name, handler) click to toggle source

Off: stop listening to event / specific callback

# File lib/rbminivents.rb, line 16
def off(name, handler)
  @handlers[name] ||= []
  @handlers[name].delete(handler)
end
on(name, &handler) click to toggle source

On: listen to events

# File lib/rbminivents.rb, line 9
def on(name, &handler)
  @handlers[name] ||= []
  @handlers[name] << handler
  handler
end