From: Patrick Hurley Date: 2005-12-08T14:00:47+09:00 Subject: Re: increasing counter whithin loop? > On 12/7/05, mental@rydia.net wrote: > > > > A lot of Ruby's clarity comes not from being able to write things > > clearly in the "raw" language, but from being able to easily > > customize the language for your needs. +1 You can also try something like this: module Enumerable def each_with_gathered_dups group = [] each do |elem| if elem == group.last group << elem else begin yield group unless group.empty? ensure group = [elem] end end end yield group end end # which might work something like this a = [1, 2, 2, 2, 3, 4, 5, 5, 6, 6, 6, 6] a.each_with_gathered_dups { |g| p g } outputing [1] [2, 2, 2] [3] [4] [5, 5] [6, 6, 6, 6] Notice I chose to wrap the dups as arrays, and single elements as single element arrays, just another approach, but the lesson is don't fight the language, grow it to your problem (and learn how to make better method names than I do :-) pth