2007-12-21 08:48:59 +01:00
|
|
|
module ActiveSupport #:nodoc:
|
|
|
|
module CoreExtensions #:nodoc:
|
|
|
|
module Array #:nodoc:
|
|
|
|
module RandomAccess
|
2010-05-25 19:45:45 +02:00
|
|
|
# This method is deprecated because it masks Kernel#rand within the Array class itself,
|
|
|
|
# which may be used by a 3rd party library extending Array in turn. See
|
|
|
|
#
|
|
|
|
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4555
|
|
|
|
#
|
|
|
|
def rand # :nodoc:
|
|
|
|
ActiveSupport::Deprecation.warn 'Array#rand is deprecated and will be removed in Rails 3. Use "random_element" instead', caller
|
|
|
|
random_element
|
|
|
|
end
|
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
# Returns a random element from the array.
|
2010-05-25 19:45:45 +02:00
|
|
|
def random_element
|
2007-12-21 08:48:59 +01:00
|
|
|
self[Kernel.rand(length)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|