Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A tiny, tiny hooks framework. Really, very tiny.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 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.