Last Updated: February 25, 2016
·
2.703K
· pragtob

Introducing after_do: after/before method callbacks in Ruby

I just released a new version of a gem called after_do which you can use to easily add callbacks before/after a method is executed. I also wrote an introduction blog post about it.

It basically works like this:

MyClass.after :some_method do whatever_you_want end
# or/and
MyClass.before :some_method do pure_magic end

It mainly borrows ideas from aspect oriented programming - e.g. doing something after/before several just loosely related methods are called. One of the most used examples is logging - it clutters the code of many methods of many classes. With this you can get it out of there and have it all nicely packed up in one file.

Go ahead and check it out!