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.)
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.
Have a look at Enumerator#each_slice and Enumerator#each_cons
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?
find yet. Is there any hint where I could start searching?
Certainly. I use www.ruby-doc.org - specifically the “core api” and
“standard api” sections.
Sam
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.