Wrap text
Report abuse
module ActiveRecord
class Base
class << self
def find(*args)
options = args.extract_options!
validate_find_options(options)
set_readonly_option!(options)
case args.first
when :first then find_initial(options)
when :last then find_last(options)
when :all then find_every(options)
when :random then find_random(options)
else find_from_ids(args, options)
end
end
def random
find(:first, :offset => rand(self.count))
end
private
def find_random(options)
results = find_every(options)
results[rand(results.count)]
end
end
end
end