aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-05 01:13:37 +0200
committerXavier Noria <fxn@hashref.com>2010-06-05 01:15:17 +0200
commit67a43554f153a3ddb97039b5fac305c0619dd372 (patch)
treedefe65bc4dec8844525c93a348dfc9a97eacf237 /railties/guides/source/active_support_core_extensions.textile
parent6401ab587021b78c3dc5e4a5ac831823a9258481 (diff)
downloadrails-67a43554f153a3ddb97039b5fac305c0619dd372.tar.gz
rails-67a43554f153a3ddb97039b5fac305c0619dd372.tar.bz2
rails-67a43554f153a3ddb97039b5fac305c0619dd372.zip
removes Array#random_element and backports Array#sample from Ruby 1.9, thanks to Marc-Andre Lafortune
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile16
1 files changed, 13 insertions, 3 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index de82e871a6..6c3a005daf 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1927,13 +1927,23 @@ Similarly, +from+ returns the tail from the element at the passed index on:
The methods +second+, +third+, +fourth+, and +fifth+ return the corresponding element (+first+ is builtin). Thanks to social wisdom and positive constructiveness all around, +forty_two+ is also available.
-You can pick a random element with +random_element+:
+NOTE: Defined in +active_support/core_ext/array/access.rb+.
+
+h4. Random Access
+
+Active Support backports +sample+ from Ruby 1.9:
+
+You can pick a random element with +sample+:
<ruby>
-shape_type = [Circle, Square, Triangle].random_element
+shape_type = [Circle, Square, Triangle].sample
+# => Square, for example
+
+shape_types = [Circle, Square, Triangle].sample(2)
+# => [Triangle, Circle], for example
</ruby>
-NOTE: Defined in +active_support/core_ext/array/access.rb+.
+NOTE: Defined in +active_support/core_ext/array/random_access.rb+.
h4. Options Extraction