I've inherited an app that uses a lot of Service Objects, which inherit from ApplicationService
:
class ApplicationService
class InternalServiceError < StandardError; end
include ActiveModel::Model
def self.execute(*args)
new(*args).execute
end
def self.call(...)
new(...).call
end
end
Why would there be both an execute
and a call
method? It seems odd to have both since they are both instantiating an instance of the class.
Also, what is (...)
for? I've not seen that argument style before. How is it different to (*args)
or (**args)
?
I found some internal docs that revealed that execute
is legacy and with advent of Ruby 2.7 it was decided to replace it with call
, but nobody has updated the base class to remove execute
.
Thanks to @Stefan for the link to explain call forwarding syntax (...)