From: Brad Ediger Date: 2009-06-12T02:54:01+09:00 Subject: Re: Idiomatic way to detect first/last iteration? --00163646dc8ca4033f046c1646c8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Jun 11, 2009 at 12:52 PM, Matthew K. Williams wrote: > I expect there's a better way to do this, but as a quick dash-off.... > > x=%w(the big fat cat) > > x.each do |y| > print "first " if (y==x.first) > print "last " if (y==x.last) > puts y > end > Only if all of your elements are unique... x=%w(1 2 1 3 4 3) --00163646dc8ca4033f046c1646c8--