From: Carlos Date: 2003-05-30T21:04:43+09:00 Subject: Re: Iteration - last detection > Here is a module that implements it, but you should include it in every [...] Hmmm... this should handle the #each nesting properly (but still has problems with last, break, etc, I think): --- oe.rb~ 2003-05-30 12:56:28.000000000 +0200 +++ oe.rb 2003-05-30 14:00:52.000000000 +0200 @@ -18,6 +18,7 @@ alias_method :#{old_each}, :each def each(*a,&b) + old_last=last? element = nil flag = false #{old_each}(*a) { |e| @@ -25,6 +26,9 @@ @__last_iteration__=false } b.call element if flag + Thread.current.instance_eval { + @__last_iteration__=old_last + } flag=true element=e } @@ -34,7 +38,7 @@ } b.call element Thread.current.instance_eval { - @__last_iteration__=false + @__last_iteration__=old_last } end end