Skip to content
A tiny, tiny hooks framework. Really, very tiny.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
.gitignore
LICENSE
README.md
Rakefile
micro_hooks.gemspec

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.