Ruby 在此特定代码中,类方法与实例方法
我的班级看起来像这样Ruby 在此特定代码中,类方法与实例方法,ruby,Ruby,我的班级看起来像这样 class ThirdPartyServiceImport def posts execute!('12313', 'EFewfeHUIfaieuh8328') end def comments execute!('333434', 'EwaefawefFewfeHUIh8328') end private def execute!(identifier, key) client = ThirdPartyClient.
class ThirdPartyServiceImport
def posts
execute!('12313', 'EFewfeHUIfaieuh8328')
end
def comments
execute!('333434', 'EwaefawefFewfeHUIh8328')
end
private
def execute!(identifier, key)
client = ThirdPartyClient.new(key)
client.run_query(identifier: identifier)
end
end
我应该使用类方法吗?若然,原因为何
此代码负责访问第三方API并从中导入内容。对于这里的示例,我只是假装我的方法将返回的内容是Posts和Comments
此内容是我的应用程序所依赖的数据,定期使用这些方法/此类来刷新数据。我认为实例方法很好,下面是一篇优秀的博客文章,介绍了使用实例而不是滥发类方法的一些优点
这段代码实际上是做什么的?