From: Gennady Date: 2003-05-30T05:13:51+09:00 Subject: Re: Iteration - last detection > > 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] With arrays you can also do this as a[0..-2].each { |n| ... } p a.last A little bit less typing. For a hash you can iterate in this manner over Hash#keys. > > hope this is satisfactory... > > /Anders > > -- > dc -e > 4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap > > >