Gnanavel <gnanavel.s / gmail.com> 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