aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-05-22 14:14:56 -0400
committerGitHub <noreply@github.com>2018-05-22 14:14:56 -0400
commitfa9d01d7ddbe18cabd31bcc86b6aa86ac02eff48 (patch)
treea3e8f280ccda596e1590b39807460d0c6d7de744 /guides
parent7ee898ca18797c70ed71605087474032e2289909 (diff)
parente04a79e772fc9d016d73138c3f322212f3b6ead7 (diff)
downloadrails-fa9d01d7ddbe18cabd31bcc86b6aa86ac02eff48.tar.gz
rails-fa9d01d7ddbe18cabd31bcc86b6aa86ac02eff48.tar.bz2
rails-fa9d01d7ddbe18cabd31bcc86b6aa86ac02eff48.zip
Merge pull request #32938 from utilum/range_case_equality
Allow Range#=== and Range#cover? on Range
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_support_core_extensions.md19
1 files changed, 12 insertions, 7 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index cde217e1e4..057651e0cf 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -2889,9 +2889,9 @@ As the example depicts, the `:db` format generates a `BETWEEN` SQL clause. That
NOTE: Defined in `active_support/core_ext/range/conversions.rb`.
-### `include?`
+### `===`, `include?`, and `cover?`
-The methods `Range#include?` and `Range#===` say whether some value falls between the ends of a given instance:
+The methods `Range#===`, `Range#include?`, and `Range#cover?` say whether some value falls between the ends of a given instance:
```ruby
(2..3).include?(Math::E) # => true
@@ -2900,18 +2900,23 @@ The methods `Range#include?` and `Range#===` say whether some value falls betwee
Active Support extends these methods so that the argument may be another range in turn. In that case we test whether the ends of the argument range belong to the receiver themselves:
```ruby
+(1..10) === (3..7) # => true
+(1..10) === (0..7) # => false
+(1..10) === (3..11) # => false
+(1...9) === (3..9) # => false
+
(1..10).include?(3..7) # => true
(1..10).include?(0..7) # => false
(1..10).include?(3..11) # => false
(1...9).include?(3..9) # => false
-(1..10) === (3..7) # => true
-(1..10) === (0..7) # => false
-(1..10) === (3..11) # => false
-(1...9) === (3..9) # => false
+(1..10).cover?(3..7) # => true
+(1..10).cover?(0..7) # => false
+(1..10).cover?(3..11) # => false
+(1...9).cover?(3..9) # => false
```
-NOTE: Defined in `active_support/core_ext/range/include_range.rb`.
+NOTE: Defined in `active_support/core_ext/range/compare_range.rb`.
### `overlaps?`