From: Kendall Gifford Date: 2009-06-12T01:43:16+09:00 Subject: Idiomatic way to detect first/last iteration? Hi there, is there any recognized ruby idiomatic way for detecting when you're on the first and/or last iteration over a collection? Or, if not, anyone know of any tricky ways? Specifically, I'm trying to avoid using each_with_index (as shown below): genres = %w{ classical punk rock jazz } genres.each_with_index do |genre, i| desc = "one of my favorites" desc = "my absolute favorite" if i.zero? desc = "my least fav. of all my favorites" if i + 1 == genres.length puts "#{genre} is #{desc}" end I just don't like having to compare an index value (especially as when detecting the final iteration) and hate even having it as a loop parameter unless absolutely necessary. I know, I'm picky. Just wanted to beat the bushes and see if any cool alternatives pop up.