Skip to content
A tiny, tiny hooks framework. Really, very tiny.
Ruby
Find file
Latest commit 9f0756c Feb 13, 2009 @jnicklas added gemspec
Failed to load latest commit information.
lib Initial checkin. Feb 13, 2009
spec Initial checkin. Feb 13, 2009
.gitignore Initial checkin. Feb 13, 2009
LICENSE Initial checkin. Feb 13, 2009
README.md Initial checkin. Feb 13, 2009
Rakefile Initial checkin. Feb 13, 2009
micro_hooks.gemspec added gemspec Feb 13, 2009

README.md

MicroHooks

Hooks are a mechanism for allowing other code to hook into your library in a very modular way. It's basically a really, really simple way to implement callbacks. It works like this:

Create a class, include MicroHooks and add some hooks in your methods.

require 'rubygems'
require 'micro_hooks'

class SomeClass

  include MicroHooks

  def foo
    hook :before_foo
    puts "Monkey"
    hook :after_foo
  end

  def baz
    puts "-> Ape"
  end

  def quox
    puts "-> Bear"
  end

end

You can then add some hooks

SomeClass.before :foo, :baz
SomeClass.after :foo, :quox

s = SomeClass.new
s.foo

The result here would be:

-> Ape
Monkey
-> Bear

You can also pass arguments to hooks.

def foo(bar)
  hook :quox, bar
end

def baz(bar)

end

If baz is added as a hook on quox, then baz will be called with bar as an argument. (are you following?)

Something went wrong with that request. Please try again.