Module: AfterDo

Defined in:
lib/after_do.rb,
lib/after_do/version.rb

Overview

The after_do library adds callbacks to methods in Ruby. Before using this with any class, said class has to extend the AfterDo module first e.g. MyClass.extend AfterDo MyClass.after :some_method do awesome_stuff end

More information at the github page: https://github.com/PragTob/after_do

Defined Under Namespace

Classes: CallbackError, NonExistingMethodError

Constant Summary collapse

ALIAS_PREFIX =

The prefix for the copies of the original methods made by after_do

'__after_do_orig_'
VERSION =

::nodoc::

'0.4.0'

Instance Method Summary collapse

Instance Method Details

#after(*methods, &block) ⇒ Object

A method to add a callback to a method or a list of methods to be executed after the original method was executed. E.g.:

MyClass.after :some_method do awesome_stuff end

It can only take a list of methods after which a block should be executed:

MyClass.after :method1, :method2, :method3 do puts 'jay!' end

The list can also be an Array.



25
26
27
# File 'lib/after_do.rb', line 25

def after(*methods, &block)
  _after_do_define_callback(:after, methods, block)
end

#before(*methods, &block) ⇒ Object

This method works much like .after - except blocks are executed before the method is called.



31
32
33
# File 'lib/after_do.rb', line 31

def before(*methods, &block)
  _after_do_define_callback(:before, methods, block)
end

#remove_all_callbacksObject

Removes all callbacks attached to methods in the module.



36
37
38
# File 'lib/after_do.rb', line 36

def remove_all_callbacks
  @_after_do_callbacks = _after_do_basic_hash
end