Report abuse


			
class ActiveRecord::Base
  def self.lazy_find(args = {}, &block)
    total = self.count(*args)

    count = 0
    args[:limit] ||= 100
    args[:offset] = count

    while items = self.find(:all, args) and not items.empty?
      items.each do |item|
        args[:offset] += 1
        block.call item        
      end
      puts "#{sprintf("%2.2f", 100 * count.to_f / total)}%: #{count}\n"
    end
  end
end