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
executeis legacy and with advent of Ruby 2.7 it was decided to replace it withcall, but nobody has updated the base class to removeexecute.Thanks to @Stefan for the link to explain call forwarding syntax
(...)