Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature #19839] Add Range#overlap? #8242

Merged
merged 1 commit into from Sep 16, 2023
Merged

Conversation

shouichi
Copy link
Contributor

Add a method that returns true if two range overlap, otherwise false.

(0..10).overlap?(5..15) #=> true
(0..10).overlap?(20..30) #=> false

@baweaver
Copy link
Contributor

Oooo, I like this a lot, and have very frequently made helpers for this.

range.c Show resolved Hide resolved
Add a method that returns true if two range overlap, otherwise false.

```
(0..10).overlap?(5..15) #=> true
(0..10).overlap?(20..30) #=> false
```
@nobu nobu merged commit e9b503f into ruby:master Sep 16, 2023
90 checks passed
@shouichi shouichi deleted the range-overlap branch September 17, 2023 01:26
yahonda added a commit to yahonda/rails that referenced this pull request Sep 19, 2023
This commit uses Ruby 3.3 `Range#overlap?` that has been added to Ruby via ruby/ruby#8242 .
Rails 7.1 renames `Range#overlaps?` to `Range#overlap?` via rails#48565 ,
This commit is not feasible to backport because there is no `Range#overlap?` in Rails 7.0.z

This commit addresses the CI faiilure at https://buildkite.com/rails/rails/builds/99745#018a9ea8-82f0-40a6-90c3-cdaa6dabebab/1092-1095
because without this commit, it shows `warning: method redefined; discarding old overlap?`.
```ruby
$ ruby -v
ruby 3.3.0dev (2023-09-16T05:57:19Z master e9b503f1bb) [x86_64-linux]
$ RAILS_STRICT_WARNING=true bundle exec ruby -w -Itest test/core_ext/range_ext_test.rb
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/core_ext/range/overlap.rb:7: warning: method redefined; discarding old overlap?
Running 46 tests in a single process (parallelization threshold is 50)
Run options: --seed 583

\# Running:

..............................................

Finished in 0.011672s, 3940.9670 runs/s, 4883.3722 assertions/s.
46 runs, 57 assertions, 0 failures, 0 errors, 0 skips
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants