aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorSebastian Martinez <sebastian@wyeworks.com>2011-04-15 14:08:37 -0300
committerSebastian Martinez <sebastian@wyeworks.com>2011-04-15 14:08:37 -0300
commit4dd84c8db06ddb56468401a478399c995c9604c1 (patch)
tree82d86b7b10a595f129474dcdb6bc6d74a9630f92 /activesupport/lib
parentba8a71588d8f3206b92c3e176c0b55529904a488 (diff)
downloadrails-4dd84c8db06ddb56468401a478399c995c9604c1.tar.gz
rails-4dd84c8db06ddb56468401a478399c995c9604c1.tar.bz2
rails-4dd84c8db06ddb56468401a478399c995c9604c1.zip
Improved Array#sample documentation
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/array/random_access.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/random_access.rb b/activesupport/lib/active_support/core_ext/array/random_access.rb
index ab1fa7cd5b..0bf510e39a 100644
--- a/activesupport/lib/active_support/core_ext/array/random_access.rb
+++ b/activesupport/lib/active_support/core_ext/array/random_access.rb
@@ -1,7 +1,9 @@
class Array
# Backport of Array#sample based on Marc-Andre Lafortune's https://github.com/marcandre/backports/
# Returns a random element or +n+ random elements from the array.
- # If the array is empty and +n+ is nil, returns <tt>nil</tt>. if +n+ is passed, returns <tt>[]</tt>.
+ # If the array is empty and +n+ is nil, returns <tt>nil</tt>.
+ # If +n+ is passed and its value is less than 0, it raises an +ArgumentError+ exception.
+ # If the value of +n+ is equal or greater than 0 it returns <tt>[]</tt>.
#
# [1,2,3,4,5,6].sample # => 4
# [1,2,3,4,5,6].sample(3) # => [2, 4, 5]