aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array
diff options
context:
space:
mode:
authorSebastian Martinez <sebastian@wyeworks.com>2011-04-15 14:13:10 -0300
committerSebastian Martinez <sebastian@wyeworks.com>2011-04-15 14:13:10 -0300
commit91761b775ce1f028486dc3483904795e9c028ed6 (patch)
tree0bd820ea2a0e859bea0fac69c68ab4763706b932 /activesupport/lib/active_support/core_ext/array
parent4dd84c8db06ddb56468401a478399c995c9604c1 (diff)
downloadrails-91761b775ce1f028486dc3483904795e9c028ed6.tar.gz
rails-91761b775ce1f028486dc3483904795e9c028ed6.tar.bz2
rails-91761b775ce1f028486dc3483904795e9c028ed6.zip
Added an example of exception situation on Array#sample docs
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array')
-rw-r--r--activesupport/lib/active_support/core_ext/array/random_access.rb9
1 files changed, 5 insertions, 4 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 0bf510e39a..9eba4642b8 100644
--- a/activesupport/lib/active_support/core_ext/array/random_access.rb
+++ b/activesupport/lib/active_support/core_ext/array/random_access.rb
@@ -5,10 +5,11 @@ class Array
# 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]
- # [].sample # => nil
- # [].sample(3) # => []
+ # [1,2,3,4,5,6].sample # => 4
+ # [1,2,3,4,5,6].sample(3) # => [2, 4, 5]
+ # [1,2,3,4,5,6].sample(-3) # => ArgumentError: negative sample number
+ # [].sample # => nil
+ # [].sample(3) # => []
def sample(n=nil)
return self[Kernel.rand(size)] if n.nil?
n = n.to_int