From: Martin DeMello Date: 2003-05-30T16:26:42+09:00 Subject: Re: Iteration - last detection dblack@superlink.net wrote: > module Enumerable > def each_with_last > n = -1 > each { n += 1 } > each_with_index {|e,i| yield(e, i == n)} > end > end > > It benchmarks a bit faster than yours, for arrays of size 10 to 10000, > but not wildly so. My flag version benchmarks fater still user system total real flag: 146.570000 0.270000 146.840000 (167.307243) index: 190.220000 1.170000 191.390000 (219.334280) Also, if we're really bumming cycles (and depending on how differently you want to treat the last element), you could yield 0..n-1 and return n, saving the two-valued yield and the test in the client method. martin