Uberhook
The Uberhook gem allows you to define before
and after
hooks for your classes and models.
Installation
$ gem install uberhook
Or add the following line to your application's Gemfile and run $ bundle
afterwards.
gem 'uberhook'
Usage
require 'uberhook'
class Car
include Uberhook::Abstract
before :drive do
p 'start engine'
end
after :drive do
p 'turn radio on'
end
def drive
p 'drive'
end
end
beatle = Car.new
beatle.drive
# Output:
# start engine
# drive
# turn radio on
Use the Uberhook::Base
module to define class hooks.
require 'uberhook'
class Dance
include Uberhook::Base
instance_hook :after, :step_one do
p 'two!'
end
def step_one
p 'one!'
end
class_hook :before, :rock do
p 'prepare'
end
def self.rock
p 'and rock'
end
end
waltz = Dance.new
waltz.step_one
# Output:
# one!
# two!
Dance.rock
# Output:
# prepare
# and rock