[ANN] HookR 1.0.0

2008 December 5
by avdi

I’m pleased to announce the availability of HookR 1.0.0

Description

HookR is a publish/subscribe callback hook facility for Ruby.

What is it?

HookR can be understood in a few different ways.

  • If you are familiar with Events and Event Listeners in Java or C#(VS.71).aspx; Hooks in Emacs-lisp; or signals-and-slots as implemented in the Qt, Boost.Signals, or libsigc++ frameworks – HookR provides a very similar facility.
  • If you’ve ever used the Observer standard library, but wished you could have more than one type of notification per observable object, HookR is the library for you.
  • HookR is an easy way to add Rails-style before- and after-filters to your own classes.
  • HookR is an Inversion-of-Control framework in that it makes it easy to write event-driven code.
  • HookR is a way to support a limited, structured form of Aspect Oriented Programming (AOP) where the advisable events are explicitly defined.

What HookR is not:

  • HookR is not (yet) an asynchronous event notification system. No provision is made for multi-threaded operation or event queueing.
  • HookR will show you a good time, but it will not make you breakfast in the morning.

Synopsis

  require 'rubygems'
  require 'hookr'

  class ZeroWing
    include HookR::Hooks
    define_hook :we_get_signal, :message

    def start_game
      execute_hook(:we_get_signal, "How are you gentlemen?")
    end

    def bomb(event, message)
      puts "somebody set us up the bomb!"
    end

    we_get_signal do |event, message|
      puts "Main screen turn on!"
      puts "Cats: #{message}"
    end

    we_get_signal :bomb

  end

  zw = ZeroWing.new
  zw.we_get_signal do
    puts "Take off every zig!"
  end

  zw.start_game
  # >> Main screen turn on!
  # >> Cats: How are you gentlemen?
  # >> somebody set us up the bomb!
  # >> Take off every zig!

Get it Now

Pull your hat way down over your eyes, drive over to the your local red-light district, and type:

sudo gem install hookr

For more information, check out the website: http://hookr.rubyforge.org

Bookmark and Share
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
  • You have no idea the degree of cognitive dissonance this evoked when I stumbled across it before my first morning coffee...
blog comments powered by Disqus