From: Xavier Noria Date: 2007-04-30T18:13:39+09:00 Subject: Re: cyclic array On Apr 30, 2007, at 3:43 AM, Rick DeNatale wrote: > On 4/28/07, Xavier Noria wrote: > >> >> This is a possible approach: >> >> module Enumerable >> def each_cycle(window, start=0) >> (start...length+start).each do |i| >> yield((i..i+window).map {|n| self[n % length]}) >> end >> end >> end > > This method won't work for Enumerables in general, although I guess it > does work for Arrays. > > Not all enumerables have one or both length or [] methods. Oh right, thank you. I don't know why ri Enumerable lists length here, looks like it is getting non-core methods from somewhere else. I overlooked [] though. The OP wanted this for an Array, it would certainly work there. -- fxn