List Info

Thread: How to use iterator for access to multiple elements?




How to use iterator for access to multiple elements?
user name
2006-09-25 09:35:13
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


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )