aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array/random_access.rb
blob: 5338836b293e859660271748e983f54f0b6f0707 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Array
  # 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, use random_element instead", caller
    random_element
  end

  # Returns a random element from the array.
  def random_element
    self[Kernel.rand(length)]
  end
end