Ruby on rails 什么是优雅的';ruby';改变循环的方式(在rails中,如果有必要的话)';在使用list.each时,每n次迭代执行一次函数?

Ruby on rails 什么是优雅的';ruby';改变循环的方式(在rails中,如果有必要的话)';在使用list.each时,每n次迭代执行一次函数?,ruby-on-rails,ruby,loops,Ruby On Rails,Ruby,Loops,什么是优雅的“ruby”方法,可以每N次迭代修改一个循环的函数?我不希望使用(1..50)。每个都使用| I |,因为我希望迭代列表对象中的每个对象 objects.each do |object| #Do this with object information #Do not do this if this is the third time through the loop end 不知道我可以用索引。真棒。Ecnalyr有几个(非常有用的方法每个带有XXX的\u(带

什么是优雅的“ruby”方法,可以每N次迭代修改一个循环的函数?我不希望使用
(1..50)。每个都使用| I |
,因为我希望迭代列表
对象中的每个对象

  objects.each do |object|
   #Do this with object information
   #Do not do this if this is the third time through the loop
  end

不知道我可以用索引。真棒。Ecnalyr有几个(非常有用的方法
每个带有XXX的\u
(带有对象、索引、每个\u切片等)@Ecnalyr。我不知道我可以使用\u索引。真棒。有几个(非常有用的方法
每个带有XXX的\u
(带有对象、索引、每个\u切片等)@Ecnalyr。
objects.each_with_index do |object, idx|
   if idx == 2 # third time

   # or
   # if idx % 3 == 2 # every third time

     # do special thing
   else
     # do normal thing
   end
end