Class Array
In: lib/will_paginate/core_ext.rb
lib/will_paginate/array.rb
Parent: Object

helper to check for method existance in ruby 1.8- and 1.9-compatible way because `methods`, `instance_methods` and others return strings in 1.8 and symbols in 1.9

  ['foo', 'bar'].include_method?(:foo) # => true

Methods

Public Instance methods

Paginates a static array (extracting a subset of it). The result is a WillPaginate::Collection instance, which is an array with a few more properties about its paginated state.

Parameters:

  • :page - current page, defaults to 1
  • :per_page - limit of items per page, defaults to 30
  • :total_entries - total number of items in the array, defaults to array.length (obviously)

Example:

  arr = ['a', 'b', 'c', 'd', 'e']
  paged = arr.paginate(:per_page => 2)      #->  ['a', 'b']
  paged.total_entries                       #->  5
  arr.paginate(:page => 2, :per_page => 2)  #->  ['c', 'd']
  arr.paginate(:page => 3, :per_page => 2)  #->  ['e']

This method was originally suggested by Desi McAdam and later proved to be the most useful method of will_paginate library.

[Validate]