Module: Beacon

Defined in:
lib/beacon.rb

Class Method Summary collapse

Class Method Details

.fire(event, *args) ⇒ Object

Fire an event to be processed by all the watchers. You pass the event name and any arguments you want passed to the event handlers.

Beacon.fire(:some_event, "an argument", 2, "another")


6
7
8
9
10
# File 'lib/beacon.rb', line 6

def self.fire(event, *args)
  events[event].each do |callback|
    callback.call(*args)
  end
end

.watch(event, &handler) ⇒ Object

Register a callback for a given event. Each time you call fire then all the callbacks registered for that name will be called in order.

Beacon.watch :some_event do |foo, bar, baz|
  # do stuff with foo, bar, and baz
end


18
19
20
# File 'lib/beacon.rb', line 18

def self.watch(event, &handler)
  events[event] << handler
end