From: Xavier Noria Date: 2007-05-01T22:05:36+09:00 Subject: Re: cyclic array On Apr 30, 2007, at 11:13 AM, Xavier Noria wrote: > 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 It took me a while to discover where that non-core Enumerable#length reported by ri/fri comes from, it is defined by RGL in the file rgl-0.2.3/lib/rgl/base.rb I've learned that ri offers --system the hard way :-). -- fxn