Separation Of Concerns In Ruby
I once worked in a Java project where cross-cutting concerns where a big issue. One of the problems was logging. Error handling was another. Logging and error handling code was sprinkled throughout 15 MB source code. Fixing it was no picnic. Today, I once again had reason to reflect on how to separate cross-cutting concerns. This time in Ruby. For example, if I have a Ruby class like this: class TemperatureConverter def celsius_to_fahrenheit(c) 9.0 / 5 * c + 32 end def fahrenheit_to_celsius(f) 5.0 / 9 * (f - 32) end end it would be very nice if I could add a cross-cutting concern without having to modify the original code. I would like make the methods in the class loggable by opening the class and declaring that I want logging, like this: class TemperatureConverter loggable_method :celsius_to_fahrenheit, :debug loggable_method :fahrenheit_to_celsius, :debug end How do I do that? I can add loggable_method as an instance method to Object . Object is the parent class of all other cla