Module: Uberhook

Defined in:
lib/uberhook.rb

Overview

Include the Uberhook module to define ‘before’ and ‘after’ hooks for your classes and models.

class Car
  include Uberhook

  before :drive, :start_engine

  def drive
    puts 'Now lets drive.'
  end

  def start_engine
    puts 'First start the engine.'
  end
end

beatle = Car.new
beatle.drive

Output:

First start the engine.
Now lets drive.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
28
# File 'lib/uberhook.rb', line 25

def self.included(base)
  base.extend ClassMethods
  base.instance_variable_set :@hooks, {}
end