Module: AfterDo::Class

Defined in:
lib/after_do.rb

Overview

These methods become available on a class after the AfterDo module was extended (e.g. extending the AfterDo module results in extending AfterDo::Class)

Instance Method Summary collapse

Instance Method Details

#_after_do_callbacksObject

It’s not really meant for you to mess with - therefore the _after_do prefix (it’s an internal structure but needs to be accessible) from instances. However it’s an accessor for the after_do callbacks associated with this class. This is a hash of the following form:

{after:  {method: [callback1, callback2, ...]},
 before: {method: [callback1, callback2, ...]}


57
58
59
# File 'lib/after_do.rb', line 57

def _after_do_callbacks
  @_after_do_callbacks || _after_do_basic_hash
end

#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.



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

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.



41
42
43
# File 'lib/after_do.rb', line 41

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

#remove_all_callbacksObject

Removes all callbacks attach to methods in this class.



46
47
48
# File 'lib/after_do.rb', line 46

def remove_all_callbacks
  @_after_do_callbacks = _after_do_basic_hash
end