From: Vincent Fourmond Date: 2006-12-22T06:55:36+09:00 Subject: Re: prob with each_with_index 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.fourmond.neuf.fr/