aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
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
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')
-rw-r--r--railties/guides/source/3_0_release_notes.textile1
-rw-r--r--railties/guides/source/active_support_core_extensions.textile16
2 files changed, 14 insertions, 3 deletions
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index 2a8d7fbcdb..75c03be87c 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -512,6 +512,7 @@ These are the main changes in Active Support:
* Active Support no longer provides vendored versions of "TZInfo":http://tzinfo.rubyforge.org/, "Memcache Client":http://deveiate.org/projects/RMemCache/ and "Builder":http://builder.rubyforge.org/, these are all included as dependencies and installed via the <tt>bundle install</tt> command.
* Safe buffers are implemented in <tt>ActiveSupport::SafeBuffer</tt>.
* Added <tt>Array.uniq_by</tt> and <tt>Array.uniq_by!</tt>.
+* Removed <tt>Array#rand</tt> and backported <tt>Array#sample</tt> from Ruby 1.9.
* Fixed bug on +TimeZone.seconds_to_utc_offset+ returning wrong value.
* Added <tt>ActiveSupport::Notifications</tt> middleware.
* <tt>ActiveSupport.use_standard_json_time_format</tt> now defaults to true.
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