How can I write a conditional :each in ruby more succinctly?

Viewed 65

I'm not sure how to write this code more cleanly in ruby? The only thing that differs is the iterator.

  if items.respond_to?(:find_each)
    items.find_each do |item|
      output_item(csv, item)
    end
  else
    items.each do |item|
      output_item(csv, item)
    end
  end
3 Answers
Related