From: Anders Borch Date: 2003-05-30T05:02:41+09:00 Subject: Re: Iteration - last detection Orion Hunter wrote: > Is there any built in functionality for iteration that will allow me to > detect when I am on the last element? This would not be hard for an > Array, using array.length, but what about a Hash? How would I know when > I am at the last element? > > _________________________________________________________________ > Protect your PC - get McAfee.com VirusScan Online > http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 > > hmmm... I cannot find a really elegant solution to this... it would have been nice to have some really good looking code solving this but sadly you will have to make do with something along these lines: # some array (could have been a hash) a = [3,4,5,6] # all but the last element a[0,a.length-1].each { |n| # insert real code here p n } # the last element p a[a.length] hope this is satisfactory... /Anders -- dc -e 4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap