Sha256: 36e193d5dd99e95e6f1a949b63b8588fd2f8b30a06858419c50e1ccb4b43fb9e
Contents?: true
Size: 608 Bytes
Versions: 7
Compression:
Stored size: 608 Bytes
Contents
# Extends the Array class with a function used to randomly choose elements. Note that if you are using Rails, ActiveSupport recently was updated to include a similar # function. This code checks for the presence of that method and does not try to replace it. They work the same though so no worries. module RandomData module ArrayRandomizer # Randomly chooses an element from an array # >> [1,2,3].rand = 3 # [].rand = nil def rand return self[Kernel.rand(self.size)] end end end unless Array.respond_to?(:rand) Array.send :include, RandomData::ArrayRandomizer end
Version data entries
7 entries across 7 versions & 1 rubygems