Module: RandomFromDb

Defined in:
lib/random_from_db.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/random_from_db.rb', line 2

def self.included(klass)
  klass.class.class_eval do
    define_method :random do |cnt|
      results = []
      cnt.times { results << self.first(offset: rand(self.count)) }
      results
    end
  end
end