From 67a43554f153a3ddb97039b5fac305c0619dd372 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 Jun 2010 01:13:37 +0200 Subject: removes Array#random_element and backports Array#sample from Ruby 1.9, thanks to Marc-Andre Lafortune --- railties/guides/source/3_0_release_notes.textile | 1 + .../guides/source/active_support_core_extensions.textile | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'railties/guides') 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 bundle install command. * Safe buffers are implemented in ActiveSupport::SafeBuffer. * Added Array.uniq_by and Array.uniq_by!. +* Removed Array#rand and backported Array#sample from Ruby 1.9. * Fixed bug on +TimeZone.seconds_to_utc_offset+ returning wrong value. * Added ActiveSupport::Notifications middleware. * ActiveSupport.use_standard_json_time_format 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+: -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 -NOTE: Defined in +active_support/core_ext/array/access.rb+. +NOTE: Defined in +active_support/core_ext/array/random_access.rb+. h4. Options Extraction -- cgit v1.2.3