Module: AOP

Extended by:
AOP
Included in:
AOP
Defined in:
lib/aop.rb

Instance Method Summary collapse

Instance Method Details

#after(klass, meth_name, &block) ⇒ Object

Intercept the meth_name method of klass and execute block after the original method

+klass+ Class that method to be intercepted belongs to
+meth_name+ Name of method to be intercepted
+block+ Code to executed before method, and can receive as parameters:
  1. the instance that has been intercepted
  2. the arguments passed to the original method


28
29
30
# File 'lib/aop.rb', line 28

def after(klass, meth_name, &block)
  intercept(klass, meth_name, :after, &block)
end

#around(klass, meth_name, &block) ⇒ Object

Intercept the meth_name method of klass and execute block before and after the original method, but needs explicit calling of a Ruby proc/lambda.

+klass+ Class that method to be intercepted belongs to
+meth_name+ Name of method to be intercepted
+block+ Code to executed before method, and can receive as parameters:
  1. the instance that has been intercepted
  2. the arguments passed to the original method
  3. the proc that, if called, will proceed with the execution of the method
  4. the proc that, if called, will abort the execution of the method returning
     whatever was passed as arguments to the block


43
44
45
# File 'lib/aop.rb', line 43

def around(klass, meth_name, &block)
  intercept(klass, meth_name, :around, &block)
end

#before(klass, meth_name, &block) ⇒ Object

Intercept the meth_name method of klass and execute block before the original method.

+klass+ Class that method to be intercepted belongs to
+meth_name+ Name of method to be intercepted
+block+ Code to executed before method, and can receive as parameters:
  1. the instance that has been intercepted
  2. the arguments passed to the original method


16
17
18
# File 'lib/aop.rb', line 16

def before(klass, meth_name, &block)
  intercept(klass, meth_name, :before, &block)
end