| Module | Hooks::ClassMethods |
| In: |
lib/hooks.rb
|
Returns the callbacks for name. Handy if you want to run the callbacks yourself, say when they should be executed in another context.
As callbacks can be static values, lambdas or methods, they‘re wrapped by Uber::Option::Value which gives you a very convenient way to execute the callback without knowing its type using Value#evaluate.
Example:
def initialize
self.class.callbacks_for_hook(:after_eight).each do |callback|
callback.evaluate(self, "create")
end
Runs callbacks in the object instance context and pass "create" as the only argument.
Like Hooks#run_hook but for the class. Note that +:callbacks+ must be class methods.
Example:
class Cat
after_eight :grab_a_beer def self.grab_a_beer(*) # and so on...
where Cat.run_hook :after_eight will call the class method grab_a_beer.