def last(limit = nil)
      if limit
        if order_values.empty?
          order(id: :desc).limit(limit).reverse
        else
          to_a.last(limit)
        end
      else
        find_last
      end
    end
def last(limit = nil)
      if limit
        if order_values.empty?
          order(id: :desc).limit(limit).reverse
        else
          to_a.last(limit)
        end
      else
        find_last
      end
    end
Find the last record (or last N records if a parameter is supplied).
 If no order is defined it will order by primary key.

   Person.last # returns the last object fetched by SELECT * FROM people
   Person.where(["user_name = ?", user_name]).last
   Person.order("created_on DESC").offset(5).last
   Person.last(3) # returns the last three objects fetched by SELECT * FROM people.

 Take note that in that last case, the results are sorted in ascending order:

   [#<Person id:2>, #<Person id:3>, #<Person id:4>]

 and not:

   [#<Person id:4>, #<Person id:3>, #<Person id:2>]