From: Dave Thomas Date: 2000-05-22T18:36:32-05:00 Subject: [ruby-talk:02934] Re: Iterators... h.fulton@att.net writes: > In an abitrary iterator, I want to know > whether I am on the first or last iteration. > For example: > > myarray.each { |x| print "{ " if iter_first? > print x > if iter_last? > print " }\n" > else > print ", " > end > } I know it's not a direct answer to your question, but in this particular case you could write print "{ #{myarray.join(', ')} }\n" If you're writing your own iterators, you could add another parameter to the block to do this, something like myarray.each_with_state { |element, state| case state when MyIterator::START ... when MyIterator::MIDDLE ... when MyIterator::END ... end } But I agree - it would be an interesting feature to think about. Dave