From: dblack@... Date: 2003-05-30T06:46:42+09:00 Subject: Re: Iteration - last detection Hi -- On Fri, 30 May 2003, ahoward wrote: > module Enumerable > def each_with_last(&block) > l = nil > each_with_index do |e, i| > block.call l, false if i > 0 > l = e > end > block.call l, true > end > end Let Ruby do more of the work for you :-) module Enumerable def each_with_last each_with_index {|e,i| yield(e, i == size-1)} end end (Hmmm... could this be the non-superfluous use of Enumerable#each_with_index (as opposed to just Array#ewi) that I've been looking for for 2.5 years? :-) David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav