Module: Spinach::Hookable::ClassMethods
- Defined in:
- lib/spinach/hookable.rb
Instance Method Summary (collapse)
-
- (Object) around_hook(hook)
Adds a new around_hook to this class.
-
- (Object) hook(hook)
Adds a new hook to this class.
Instance Method Details
- (Object) around_hook(hook)
Adds a new around_hook to this class. Every hook defines two methods used to add new callbacks and to run them around a given block of code passing a bunch of parameters and invoking them in the order they were defined.
39 40 41 42 43 44 45 46 |
# File 'lib/spinach/hookable.rb', line 39 def around_hook(hook) define_method hook do |&block| add_hook(hook, &block) end define_method "run_#{hook}" do |*args, &block| run_around_hook(hook, *args, &block) end end |
- (Object) hook(hook)
Adds a new hook to this class. Every hook defines two methods used to add new callbacks and to run them passing a bunch of parameters.
23 24 25 26 27 28 29 30 |
# File 'lib/spinach/hookable.rb', line 23 def hook(hook) define_method hook do |&block| add_hook(hook, &block) end define_method "run_#{hook}" do |*args, &block| run_hook(hook, *args, &block) end end |