From: Mark Hubbart Date: 2004-11-22T13:06:06+09:00 Subject: Re: meaning of #slice On Fri, 19 Nov 2004 22:20:12 +0900, trans. (T. Onoma) wrote: > Are Enumerator#each_slice and #enum_slice properly named? All they take is an > integer which groups the enumerator's elements: > > [1,2,3,4,5,6].to_enum.enum_slice(2).to_a > #=> [[1,2],[3,4],[5,6]] > > Yet Array#slice does nothing of the sort: > > [1,2,3,4,5,6].slice(2) > #=> 3 Array#slice takes a starting index and the optional second arg tells how many elements to take. in Enumerator#enum_slice, the starting index is pointless, so I guess they just eliminated it; so all you have left is the optional second arg, the size of the slice. Just a guess. > > Also, how does one achieve #enum_slice functionality without Enumerator using > only Array? tmp = array_to_work_with.dup until tmp.empty? do_stuff_with( tmp.slice!(0, size) ) end hth, Mark