diff options
author | Xavier Noria <fxn@hashref.com> | 2011-02-20 10:52:24 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-02-20 10:52:49 +0100 |
commit | e2d54fb3f17ac30c91d855c45060ec5518b75ec5 (patch) | |
tree | b6bee8f71f2942b4a092648d3bf7f9e963ae47a6 /railties/guides | |
parent | e984fd43d56797874c532b7d45af8240decfd5ba (diff) | |
download | rails-e2d54fb3f17ac30c91d855c45060ec5518b75ec5.tar.gz rails-e2d54fb3f17ac30c91d855c45060ec5518b75ec5.tar.bz2 rails-e2d54fb3f17ac30c91d855c45060ec5518b75ec5.zip |
documents the backported Range#cover?, and related stuff
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 9da8ecc6fc..535a048b3b 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -528,7 +528,7 @@ The default value can be also specified with a block, which is called in the con class User attr_accessor :name, :surname attr_accessor_with_default(:full_name) { - [name, surname].compact.join(" ") + [name, surname].compact.join(" ") } end @@ -2713,6 +2713,14 @@ WARNING: The original +Range#include?+ is still the one aliased to +Range#===+. NOTE: Defined in +active_support/core_ext/range/include_range.rb+. +h4. +cover?+ + +Ruby 1.9 provides +cover?+, and Active Support defines it for previous versions as an alias for +include?+. + +The method +include?+ in Ruby 1.9 is different from the one in 1.8 for non-numeric ranges: instead of being based on comparisons between the value and the range's endpoints, it walks the range with +succ+ looking for value. This works better for ranges with holes, but it has different complexity and may not finish in some other cases. + +In Ruby 1.9 the old behavior is still available in the new +cover?+, which Active Support backports for forward compatibility. For example, Rails uses +cover?+ for ranges in +validates_inclusion_of+. + h4. +overlaps?+ The method +Range#overlaps?+ says whether any two given ranges have non-void intersection: |