我该如何为类数组编写方法?

时间:2012-12-28 13:20:39

标签: ruby-on-rails ruby methods rspec

我希望能够使用以下方法像这样使用它:clear_tire_index_for Answer, Question

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

怎么做?

1 个答案:

答案 0 :(得分:3)

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