Different each iteration

Hi,
I’ve read a few days ago that rails has a each method that allows you to
speficy the number of iteration. I think the default number was 1000.
What is the name of the method?

myList.each_with_something or myList.each_something

Greg

Greg Ma wrote:

Hi,
I’ve read a few days ago that rails has a each method that allows you to
speficy the number of iteration. I think the default number was 1000.
What is the name of the method?

myList.each_with_something or myList.each_something

Greg

You can specify the batch_size as an option to a find_each method. Batch
methods should be used when your request retrieves large amounts of
data:

“When processing large numbers of records, it’s often a good idea to do
so in batches to prevent memory ballooning.”

Pale H. wrote:

Greg Ma wrote:

Hi,
I’ve read a few days ago that rails has a each method that allows you to
speficy the number of iteration. I think the default number was 1000.
What is the name of the method?

myList.each_with_something or myList.each_something

Greg

You can specify the batch_size as an option to a find_each method. Batch
methods should be used when your request retrieves large amounts of
data:

“When processing large numbers of records, it’s often a good idea to do
so in batches to prevent memory ballooning.”

There’s also in_groups_of.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

There’s also in_groups_of.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I’d forgotten about that method. In addition, you can
each_slice(integer) to divide an array. Though, ‘enumerator’ is required
in your Active Record model. I would recommend this approach if you’re
splitting arrays into columns or rows. Else, batch_size and in_groups_of
are useful for retrieving large data sets.

On 16 June 2010 09:19, Greg Ma [email protected] wrote:

myList.each_with_something or myList.each_something

Do you mean the “each_slice” method of enumerable?

http://ruby-doc.org/core/classes/Enumerable.html

does u speak about it ?
http://api.rubyonrails.org/classes/ActiveRecord/Batches/ClassMethods.html

Ivan N.
[email protected]