Simple observers for your code
Switch branches/tags
Latest commit 2ce461c Mar 20, 2012 @foca Build status badge [ci skip]
Failed to load latest commit information.
lib Allow on/trigger as aliases for watch/fire Mar 20, 2012
.travis.yml Add a .travis.yml Mar 20, 2012
LICENSE Documentation, Rakefile, gemspec Apr 22, 2009
README.rdoc Build status badge [ci skip] Mar 20, 2012



Simple observers and notifiers for your code.

The library aims to provide the simplest implementation possible. You get beacons, which are always global and can be “lit up”. Whenever you light a beacon up, everyone watching will act as instructed.


How to use this?

Whenever you want to fire an event from your code, call

def do_something
  # do your thing

In order to register listeners for that event, call :before_doing_something do "I'm about to do something"

Each time you call watch with a given name, you register a different handler for that name. Each time you call fire all handlers for that event are run, in the order they were registered.

You can use on as an alias of watch, and trigger as an alias of fire, since those seem to be popular choices among event observing libraries.

Passing arguments

If you want to pass arguments to the watchers, just pass them along in, "cuack", 3)

And you'll get them as arguments on the block that handles the message: :an_event do |object, index|
  # here object == "cuack", index == 3

Advanced handlers

Instead of blocks, can receive any object that responds to call, so if you need any advanced logic in your handlers, you can declare them like this:

class MyHandler
  def call(foo, bar=0)
    puts foo.inspect, bar
end :an_event,

Isolated events

You can include Beacon into your objects to have isolated events on a per-object basis if you need that:

class MyObservable
  include Beacon

obj = { |object, *args| puts *args }
obj.trigger(:an_event, "foo")

Installing with rubygems

gem install beacon


Clone our git repo from git:// The preffered way to send a patch is to push to a clone of the repo on github but if you want to mail me a patch or point me to a diff I won't complain. Though I'll probably take more to apply it :)


Code written by foca, with the help and ideas of halorgium, and tizoc.

The code is licensed under an MIT license. Check the LICENSE file for details.