OVERVIEW

Project Observe
Homepage https://github.com/robgleeson/observe
Documentation http://rubydoc.info/gems/observe/frames
Author Rob Gleeson

DESCRIPTION

A simple interface for adding observers to any class.
The interface is similar to and takes ideas from the 'Observable' module in the Ruby standard library.

DIFFERENCES

There are a few differences between 'Observe' and the 'Observable' module:

  • An observer is any object that responds to call.
    Proc objects can be observers out of the box.

  • Observers belong to 'groups'.
    In the example below, :ignition is a group, as is :brakes.

  • There is no changed method.
    If you want to notify observers, go ahead & use notify_observers.
    If there is state that needs to be true before observers can be notified, you can use if(…).

EXAMPLE

class Car

  include Observe

  def initialize
    add_observer(:ignition) { .. }  
    add_observer(:brakes) { .. } 
  end

  def drive
    notify_observers(:ignition)
    puts "Vroom Vroom."
    notify_observers(:brakes)
  end

end

Car.new.drive

INSTALL

gem install observe

LICENSE

See LICENSE.txt