ruby cookbook -- Looping Through Multiple Iterables in Parallel

Recipe 7.9. Looping Through Multiple Iterables in Parallel
Any object that implements the each method can be wrapped in a Generator object. If you've used Java, think of a Generator as being like a Java Iterator object. It keeps track of where you are in a particular  iteration over a data structure.

Normally, when you pass a block into an iterator method like each, that block gets called for every element in the iterator without interruption. No code outside the block will run until the iterator is done iterating. You can stop the iteration by writing a break statement inside the code block, but you can't restart a broken iteration later from the same placeunless you use a Generator.
看看api
    Generator converts an internal iterator (i.e. an Enumerable object)
     to an external iterator.
==
generator更象是把ruby的内部迭代器实现成java中的外部跌代器,这样可以随时中断,并从中断的位置继续开始。

你可能感兴趣的:(Ruby)