For a long time now, I had an open tab in my browser with Morphine‘s project page on GitHub. From first look at it, it wasn’t clear to me why would you need such a library in Ruby. I mean, I understand the need for Dependency Injection (DI) in any language (including Ruby). What I didn’t understand was, why would you need a library to do DI in Ruby?
To try and understand better, I decided to rewrite the example shown on the library page with regular class methods. Here’s the result (first file: with Morphine, second file: without Morphine):
After writing this example, it was more clear to me — the Morphine based code is more compact and clean. But on the other hand, it requires the reader of the code to get familiar with another library, where the class methods based example is straight forward to any Ruby developer.
What do you think? Would you use Morphine or go with class methods?