From: David Alan Black Date: 2002-07-11T08:54:23+09:00 Subject: Re: spliter of for...each: looping Hi -- On Thu, 11 Jul 2002, Tom Sawyer wrote: > david, > > oh, my mistake, it all ready exists! yea! > > only if it would match against -1 for last index though....oh well, > can't have everything. Here's a method with an even longer name :-) (by one character) which gives the negative indices: module Enumerable def each_with_nindex s = -1 - size each {|e| yield e, s += 1} end end %w{ a b c d e }.each_with_nindex do |e,i| if i == -1 puts "Last element: #{e}" end end # => Last element: e David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav