Module: TheHelp::ProvidesCallbacks::ClassMethods
- Defined in:
- lib/the_help/provides_callbacks.rb
Overview
Classes that include ProvidesCallbacks are extended with these ClassMethods
Instance Method Summary collapse
-
#callback(name, &block) ⇒ self
Defines a callback method on the class.
Instance Method Details
#callback(name, &block) ⇒ self
Defines a callback method on the class
The provided block will be used to define an instance method. This behaves similarly to #define_method, however it will ensure that callbacks are logged if the object has a #logger method defined.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/the_help/provides_callbacks.rb', line 58 def callback(name, &block) define_method("#{name}_without_logging", &block) define_method(name) do |*args| if defined?(logger) logger.debug("#{inspect} received callback :#{name}.") end send("#{name}_without_logging", *args) self end private name self end |