def replace(array)
      result = super
      
      # The collection is shorter then page limit? Rejoice, because
      # then we know that we are on the last page!
      if total_entries.nil? and length < per_page and (current_page == 1 or length > 0)
        self.total_entries = offset + length
      end

      result
    end
def replace(array)
      result = super
      
      # The collection is shorter then page limit? Rejoice, because
      # then we know that we are on the last page!
      if total_entries.nil? and length < per_page and (current_page == 1 or length > 0)
        self.total_entries = offset + length
      end

      result
    end
This is a magic wrapper for the original Array#replace method. It serves
 for populating the paginated collection after initialization.

 Why magic? Because it tries to guess the total number of entries judging
 by the size of given array. If it is shorter than +per_page+ limit, then we
 know we're on the last page. This trick is very useful for avoiding
 unnecessary hits to the database to do the counting after we fetched the
 data for the current page.

 However, after using +replace+ you should always test the value of
 +total_entries+ and set it to a proper value if it's +nil+. See the example
 in +create+.