From: Tim Pease Date: 2006-10-20T07:37:16+09:00 Subject: Re: How to the output in 12x8 format On 10/19/06, Li Chen wrote: > > > > > require 'enumerator' > > > > ary = (1..96).to_a > > ary.each_slice(8) {|slice| puts slice.inspect} > > > > [1, 2, 3, 4, 5, 6, 7, 8] > >....... > > > [89, 90, 91, 92, 93, 94, 95, 96] > > > Hi, > > Why should I write the code :require 'enumerator'? > > Is enumerator a module or class? > The 'each_slice' method is defined in the Enumerable module, but portions this module are not included by default. Requiring enumerator adds some extra methods to the Enumerable objects -- each_slice being one of those methods. Take a look at the Pragmatic book for some more info. It's on page 672 of the real book. I could not find any reference to each_slice in the online version. The rdoc documents aren't too helpful with this one. They just list all the Enumerable methods. It gives the impression that all of them are right there in the Array class (which is not the case). I'm done rambling now. Going home to see the little kiddo and wife :) Blessings, TwP