Skip to content
Browse files

Improved Array#sample documentation

  • Loading branch information...
1 parent ba8a715 commit 4dd84c8db06ddb56468401a478399c995c9604c1 @smartinez87 smartinez87 committed Apr 15, 2011
Showing with 3 additions and 1 deletion.
  1. +3 −1 activesupport/lib/active_support/core_ext/array/random_access.rb
View
4 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]

0 comments on commit 4dd84c8

Please sign in to comment.
Something went wrong with that request. Please try again.