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...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: prob with each_with_index
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password