Renames Array#rand -> Array#random_element

Signed-off-by: Xavier Noria <fxn@hashref.com>
This commit is contained in:
Rizwan Reza 2010-05-17 01:55:56 +04:30 committed by Xavier Noria
parent f09d8f3e68
commit 8c5e1652c7
4 changed files with 5 additions and 17 deletions

View File

@ -1,5 +1,7 @@
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
* Renames Array#rand -> Array#random_element. [Santiago Pastorino, Rizwan Reza]
* Defines prev_(month|year) in Date and Time, and deprecates last_(month|year). [fxn]
* Aliases Date#sunday to Date#end_of_week. [fxn]

View File

@ -1,16 +1,6 @@
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
end

View File

@ -368,10 +368,6 @@ class ArrayExtRandomTests < ActiveSupport::TestCase
Kernel.expects(:rand).with(3).returns(1)
assert_equal 2, [1, 2, 3].random_element
end
def test_deprecated_rand_on_array
assert_deprecated { [].rand }
end
end
class ArrayWrapperTests < Test::Unit::TestCase

View File

@ -47,7 +47,7 @@ module ApplicationTests
test "if there's no config.active_support.bare, all of ActiveSupport is required" do
use_frameworks []
require "#{app_path}/config/environment"
assert_nothing_raised { [1,2,3].rand }
assert_nothing_raised { [1,2,3].random_element }
end
test "config.active_support.bare does not require all of ActiveSupport" do
@ -57,7 +57,7 @@ module ApplicationTests
Dir.chdir("#{app_path}/app") do
require "#{app_path}/config/environment"
assert_raises(NoMethodError) { [1,2,3].rand }
assert_raises(NoMethodError) { [1,2,3].random_element }
end
end