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

Fix Range#overlaps? for beginless ranges #44757

Merged
merged 1 commit into from Mar 23, 2022

Conversation

donny741
Copy link
Contributor

Summary

Related issue #44755

Using Range#begin to get the first element of the range. Range#first raises an error when called on a beginless range.

Adding additional equality condition to cover the case when both ranges are beginless.

- `#first` raises an error when called on a beginless range.
  Using `#begin` to get the first element instead.
- Adding additional equality condition to cover the case when both
  ranges are beginless
@donny741
Copy link
Contributor Author

Adding additional equality condition to cover the case when both ranges are beginless.

Another solution can be to swap nil with -Float::INFINITY like this:

def overlaps?(other)
  cover?(other.begin || -Float::INFINITY) || other.cover?(self.begin)
end

Not sure which one is better

@tenderlove tenderlove merged commit 11451ce into rails:main Mar 23, 2022
@jonathanhefner jonathanhefner linked an issue Mar 23, 2022 that may be closed by this pull request
rafaelfranca pushed a commit that referenced this pull request Mar 23, 2022
@donny741 donny741 deleted the fix-overlaps-for-beginless-range branch May 27, 2023 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Range#overlaps? error when comparing beginless ranges
2 participants