我的班级看起来像这样......
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并从中导入内容。对于这里的例子,我只是假装我的方法返回的内容将是帖子和评论。
此内容是我的应用所依赖的数据,并且会定期使用这些方法/此类来刷新数据。
答案 0 :(得分:0)
我认为实例方法很好,这是一篇很好的博客文章,它考虑了使用实例而不是垃圾邮件类方法的一些优点。
http://blog.codeclimate.com/blog/2012/11/14/why-ruby-class-methods-resist-refactoring/