How to use iterator for access to multiple elements?

Hi,

I want to write a function that calculate the time difference between
two following elements in an array. But then I need access to both
elements in this array.

When I use an iterator I only get the actual element of the array:

array.each {|element|
  # previous = element.previous()
  element.delay = element.time - previous.time
}

Can someone tell me, how I could implement this function in a clever
way?
(A for-loop would also work, but that is not as smart as it is used to
be in Ruby.)

Thanks,
Sven

Have a look at Enumerator#each_slice and Enumerator#each_cons

Sam

···

On 9/25/06, Sven <sven@ast.dfs.de> wrote:

Hi,

I want to write a function that calculate the time difference between
two following elements in an array. But then I need access to both
elements in this array.

Sam Gentle wrote:

Have a look at Enumerator#each_slice and Enumerator#each_cons

Thanks, each_cons should be the right one for me.

But where could I find this information on my own? Only with using your
information for a web search I was able to find a little information
about it.
Also rubyforge does not help.
There has to be an easy entry point for such information that I did not
find yet. Is there any hint where I could start searching?

Thanks,
Sven

Certainly. I use www.ruby-doc.org - specifically the "core api" and
"standard api" sections.

Sam

···

On 9/25/06, Sven <sven@ast.dfs.de> wrote:

Sam Gentle wrote:
> Have a look at Enumerator#each_slice and Enumerator#each_cons
>
Thanks, each_cons should be the right one for me.

But where could I find this information on my own? Only with using your
information for a web search I was able to find a little information
about it.
Also rubyforge does not help.
There has to be an easy entry point for such information that I did not
find yet. Is there any hint where I could start searching?