aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorRizwan Reza <rizwanreza@gmail.com>2010-06-05 04:04:49 +0430
committerRizwan Reza <rizwanreza@gmail.com>2010-06-05 04:04:49 +0430
commite6f2102178b19ac8d49363b5fa145f22483c30ee (patch)
treeb5dff24210eb3f521087fe66a9b734165ad22967 /railties/guides/source/active_support_core_extensions.textile
parent1535b02a9f8e0eaa3cd3182a45d2bd7855c3809c (diff)
parent8e8cb1769f3a78c53e5b79d0ce6a08589045cfca (diff)
downloadrails-e6f2102178b19ac8d49363b5fa145f22483c30ee.tar.gz
rails-e6f2102178b19ac8d49363b5fa145f22483c30ee.tar.bz2
rails-e6f2102178b19ac8d49363b5fa145f22483c30ee.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile14
1 files changed, 11 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..30b2099be4 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1927,13 +1927,21 @@ 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:
<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