From: Martin DeMello Date: 2003-05-30T22:09:59+09:00 Subject: Re: Iteration - last detection Orion Hunter wrote: > Is there any built in functionality for iteration that will allow me to > detect when I am on the last element? This would not be hard for an Array, > using array.length, but what about a Hash? How would I know when I am at > the last element? Apologies in advance :) def each_with_hack(&block) i = nil p = proc {|i, j| eval "p = block.to_proc"} each {|j| p.call(i, false) i = j } p.call(i, true) end Seems to be about as fast (indeed, slower in some cases) than the flag version, though - is proc.call significantly slower than yield? martin