Rails ApplicationService for Service Objects同时具有execute和call



我继承了一个应用程序,它使用了很多服务对象,从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

为什么同时存在executecall方法?两者都有似乎很奇怪,因为它们都是实例化类的实例。

还有,(...)是干什么用的?我以前没见过这种论证方式。与(*args)(**args)有何不同?

我发现一些内部文档显示execute是遗留的,随着Ruby 2.7的出现,它决定用call取代它,但是没有人更新基类来删除execute

感谢@Stefan提供的解释呼叫前转语法的链接(...)

最新更新