[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: prob with each_with_index

Vincent Fourmond

12/21/2006 9:56:00 PM

shawn bright wrote:
> lo there all,
>
> i am having a problem making each_with_index do what i need it to do.
> the issue is...
>
> i need to evaluate the gpm of a flow sensor.
> we are skipping over three database entries to get the values.
> difference in value / difference in time = gpm. ok, easy enough.
>
> but this code
>
> @flow_sensor.flow_hits.each_with_index do |hit, i|
> if i > 4 # start with 3rd hit in db
No, you're starting with the 5th !!

Index are zero-based, to you need i >= 2 to get the third one.

Vince

--
Vincent Fourmond, PhD student
http://vincent.fourmon...