each_with_nindex, rocking! i'll throw that in my library, for sure.

it's really nice for building strings with dividers, e.g. "a,b,c" in
order to keep that last comma from getting appended to the end.

thanks david!

On Wed, 2002-07-10 at 17:54, David Alan Black wrote:
> 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
> 
> 
-- 
~transami

"They that can give up essential liberty to obtain a little
 temporary safety deserve neither liberty nor safety."
	-- Benjamin Franklin