【问题标题】:How should I write a method for array of classes?我应该如何为类数组编写方法?
【发布时间】:2012-12-13 18:12:36
【问题描述】:

我希望能够使用下面的方法来使用它:clear_tire_index_for Answer, Question

  def clear_tire_index_for(resource)
    resource.index.delete
    resource.tire.create_elasticsearch_index
    resource.index.refresh
  end

怎么做?

【问题讨论】:

  • resource 应该是对象还是类名?
  • resource 应该是类名

标签: ruby-on-rails ruby methods rspec


【解决方案1】:
def clear_tire_index_for(*resources)
    resources.each do |res|
        res.index.delete
        res.tire.create_elasticsearch_index
        res.index.refresh
    end
end

clear_tire_index_for Answer, Question
clear_tire_index_for Answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多