From: Gnanavel Date: 2005-08-22T15:11:18+09:00 Subject: Re: newbie: Paginating arrays(collection of image filenames) and showing progress of zipping Hi, thanks for the response, can this be combined with Ajax pagination helper? regards Gnan "Levin Alexander" wrote in message news:op.svvgufi35gefrg@mail.grundeis.net... Gnanavel wrote: > 1.I have an array of fileNames of images in the controller and I want to > paginate the images, say 20 images per page. I got the images from > Dir.glob. This could probably be more readable/efficient: module Enumerable def paginate(size) i = 0 self.inject([]) { |arr,item| (arr[i/size] ||= []) << item i += 1 arr } end end [1,2,3,4,6,7,8,9].paginate(4) #=> [[1,2,3,4],[5,6,7,8],[9]] -Levin