4 ms·
Maybe it's not that relevant here, but in most ruby on rails projects nowadays there're a lot of "service objects" which are intended to be instantiated with al
by codesnik 6y ago
Maybe it's not that relevant here, but in most ruby on rails projects nowadays there're a lot of "service objects" which are intended to be instantiated with all the needed inputs, and to have just one public method "call" without arguments, meant to be called just once.
So, from all the perspectives, they are just functions. But they're not defined as such usually, only because it'd be slightly awkward in ruby for those functions(methods, actually) to have private functions inside. Because there's no import mechanism in ruby, only mixins, which "imports" all the private methods in the module as well, polluting namespace of your class.
As a side measure, those service classes usually have a class method "call", which just passes all the args to the new instance of the class and calls the "call" on it, so you can later just do "ServiceObjectClass.call(args)" or even weirdly looking "ServiceObjectClass.(args)"
It looks very awkward IMHO, but I haven't seen better alternatives yet.