forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change on Array extension from rand => random_element [rails#4555 sta…
…te:committed] Signed-off-by: Xavier Noria <fxn@hashref.com>
- Loading branch information
1 parent
64d109e
commit 821e15e
Showing
4 changed files
with
27 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
activesupport/lib/active_support/core_ext/array/random_access.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,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 rand | ||
def random_element | ||
self[Kernel.rand(length)] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters