From: dblack@... Date: 2006-07-23T20:24:47+09:00 Subject: Re: Dividing inside iterations? Hi -- On Sun, 23 Jul 2006, Joey wrote: > Yes, but in assignement the variable goes on the left. > h = [40,20,50,200] > h.each do |num,total| The "total" there doesn't do anything; you'd just want: h.each do |num| > total = num / 24 > print "#{total} \n" Of course this could also be: puts num / 24 :-) David > end > > j`ey > http://www.eachmapinject.com > > On 7/23/06, Dominic Son wrote: >> >> Hi >> >> Learning Ruby. >> >> Is it possible to divide values while inside an iteration? >> >> for example i'd like to do something like this: >> >> h = [40,20,50,200] >> h.each do |num,total| num / 24 = total >> print "#{total} \n" end >> >> as you'd expect, there is an error because of that '/' and '=' sign in >> this iterator. >> >> so since this isn't possible what would be the best way to do what i'm >> trying to do? or perhaps my syntax is wrong >> >> thank you very much. >> >> Dominic >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me