Module | Callback::InstanceMethods |
In: |
lib/spec/callback/extensions/object.rb
|
Registers a callback for the event on the object. The callback can either be a block or a proc. When the callbacks are notified, the return value of the proc is passed to the caller.
# File lib/spec/callback/extensions/object.rb, line 5 5: def register_callback(event, callback_proc=nil, &callback_block) 6: callbacks.define(event, callback_proc, &callback_block) 7: end
Removes the callback from the event. The callback proc must be the same object as the one that was passed to register_callback.
# File lib/spec/callback/extensions/object.rb, line 11 11: def unregister_callback(event, callback_proc) 12: callbacks.undefine(event, callback_proc) 13: end
The CallbackContainer for this object.
# File lib/spec/callback/extensions/object.rb, line 25 25: def callbacks 26: @callbacks ||= CallbackContainer.new 27: end
Notifies the callbacks registered with the event on the object. Arguments can be passed to the callbacks. An error handler may be passed in as a block. If there is an error, the block is called with error object as an argument. An array of the return values of the callbacks is returned.
# File lib/spec/callback/extensions/object.rb, line 20 20: def notify_callbacks(event, *args, &error_handler) 21: callbacks.notify(event, *args, &error_handler) 22: end