Module: AfterDo
- Defined in:
- lib/after_do.rb,
lib/after_do/version.rb
Overview
The after_do library to add callbacks to methods in Ruby. Before using this with any class, that 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: 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.3.1'
Instance Method Summary collapse
-
#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.
-
#before(*methods, &block) ⇒ Object
This method works much like .after - just that the blocks are executed before the method is called.
-
#remove_all_callbacks ⇒ Object
Removes all callbacks attach to methods in this class.
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 might 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 - just that the 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_callbacks ⇒ Object
Removes all callbacks attach to methods in this class.
36 37 38 |
# File 'lib/after_do.rb', line 36 def remove_all_callbacks @_after_do_callbacks = _after_do_basic_hash end |