module RSpec::Core::Hooks

def after(scope=:each, options={}, &block)

def after(scope=:each, options={}, &block)
  hooks[:after][scope] << Hook.new(options, block)
end

def around(scope=:each, &block)

def around(scope=:each, &block)
  hooks[:around][scope] << block
end

def before(scope=:each, options={}, &block)

def before(scope=:each, options={}, &block)
  hooks[:before][scope] << Hook.new(options, block)
end

def find_hook(hook, scope, group)

def find_hook(hook, scope, group)
  hooks[hook][scope].select {|hook| hook.options_apply?(group)}
end

def hooks

def hooks
  @hooks ||= { 
    :around => { :each => [] },
    :before => { :each => [], :all => [], :suite => [] }, 
    :after => { :each => [], :all => [], :suite => [] } 
  }
end

def run_hook(hook, scope, example=nil, options={})

example. If no example is provided, just calls the hook directly.
Runs all of the blocks stored with the hook in the context of the
def run_hook(hook, scope, example=nil, options={})
  if options[:reverse]
    hooks[hook][scope].reverse.each &run_hook_in(example)
  else
    hooks[hook][scope].each &run_hook_in(example)
  end
end

def run_hook!(hook, scope, example, options={})

ensuring that they will only be run once.
Just like run_hook, except it removes the blocks as it evalutes them,
def run_hook!(hook, scope, example, options={})
  until hooks[hook][scope].empty?
    if options[:reverse] 
      example.instance_eval &hooks[hook][scope].shift
    else
      example.instance_eval &hooks[hook][scope].pop
    end
  end
end

def run_hook_filtered(hook, scope, group, example)

def run_hook_filtered(hook, scope, group, example)
  find_hook(hook, scope, group).each &run_hook_in(example)
end

def run_hook_in(example)

def run_hook_in(example)
  lambda {|hook| example ? example.instance_eval(&hook) : hook.call}
end