MyServiceController
I'm not sure the Controller
suffix makes sense to me here. Just MyService
would be best, but we want that name for the exported constant. Maybe MyServiceClass
would be tolerable since it isn't exported.
MyServiceController
I'm not sure the Controller
suffix makes sense to me here. Just MyService
would be best, but we want that name for the exported constant. Maybe MyServiceClass
would be tolerable since it isn't exported.
It seems inelegant to me to split this into two different modules, one to include, the other to extend.
the key thing (one of them) to understand here is that: class methods are singleton methods
Apparently when you create a subclass, that subclass's singleton class has # its superclass's singleton class as an ancestor.
This is a good thing. It allows class methods to be inherited by subclasses.
Class Methods Are Singleton MethodsSince in Ruby classes are objects as well, class methods are merely methods defined on a specific instance of Class.
Singleton pattern is a design pattern which restricts a class to instantiate its multiple objects.
you get a new instance of the service with each new instance of that component
So, I take it that the Service instance will not be a singleton anymore? Whereas, if provided from the root module, it will?
The stringSingleton() method of the Module object appears to be indistinguishable from a first-class function value. But the appearances are deceptive. The method isn’t free-standing: we could have used this in its body and it would have referred to the Module singleton object, even after the import. And it’s not the method which is passed to map — instead a transient function value is implicitly created to invoke the stringSingleton() method (this is a process known as eta-expansion) and it’s that function-value which is passed to map.