From: Dave Date: 2003-05-30T06:12:38+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? this might work for you, it has simplicity going for it. module Enumerable def each_but_last(&block) elements = entries last = elements.pop elements.each &block return last end end last = %w{ one two three }.each_but_last { |i| puts "each_but_last #{i}" } puts "last #{last}" Dave