You can use my little jewel - aspector to achieve this.
Using an aspectrator is regular ruby ββclasses in which you define the logic before / after / around the execution of a method. Aspects can be tested independently and applied to classes. I gave a code example below, but a complete example can be found here
class ExceptionHandler < Aspector::Base around options[:methods] do |proxy, *args, &block| begin proxy.call *args, &block rescue Exception => e puts "Exception Handling Code" end end end ExceptionHandler.apply Abc, :methods => Abc.instance_methods a = Abc.new a.func
source share