I’m writing this post as contribution to the Campagna Anti-IF (Anti-IF Campaign).

Problem

I’m developing an internal Rails plugin for widgets, it provides a class called Widget (really unconventional :-P), and each widget should inherit from it. The actual implementation provides a callback called before_render, that allows to add some logic to a widget, if implemented it’s called before the widget rendering.

Ruby doesn’t have abstract methods, so I have to check if the subclass has the implementation of mentioned method:
# Rendering code.. before_render if respond_to? :before_render # ...