From: Gary Wright Date: 2009-06-12T21:37:54+09:00 Subject: Re: Idiomatic way to detect first/last iteration? On Jun 12, 2009, at 1:37 AM, Colin Bartlett wrote: > (In Gary Wright's code, is there a reason for using Object.new. > instead of, say, the following minor changes? > previous = sigil = Object.new ##- > previous = nil ##+ > > yield(previous, 'last') unless previous == sigil ##- > yield(previous, 'last') if previous ##+ ) Because you need an object that is guaranteed to not be in the enumeration. You can't use nil because that could be the last item in the collection, which in my code would prevent the last nil from being yielded to the block. Gary Wright