使用Ruby在时间数组的处理x的元素选项 [英] Options for processing X elements of an array at a time using Ruby
本文介绍了使用Ruby在时间数组的处理x的元素选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们要处理在一个时间的阵列的1000个元素。什么是用Ruby这样的选择?
We want to process 1000 elements of an array at a time. What are the options for doing this in Ruby?
显然,一种方法是做一个简单的循环和切片从数组1000个元素,直到没有更多的元素依然存在,但很好奇,如果有其他的更优雅的选择。
Obviously, one approach is to do a simple loop and slice 1000 elements from the array until no more elements remain, but was curious if there are other more elegant options.
这是一个Rails应用程序(ROR 3.2.12)。
This is for a Rails app (RoR 3.2.12).
推荐答案
我们结束了使用 each_slice
:
array = [1,2,3,4,5,6,7,8,9,10]
array.each_slice(3) do |group|
puts group
end
这篇关于使用Ruby在时间数组的处理x的元素选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文