Skip to content

Allow Range#=== and Range#cover? on Range#32938

Merged
rafaelfranca merged 2 commits into
rails:masterfrom
utilum:range_case_equality
May 22, 2018
Merged

Allow Range#=== and Range#cover? on Range#32938
rafaelfranca merged 2 commits into
rails:masterfrom
utilum:range_case_equality

Conversation

@utilum

@utilum utilum commented May 20, 2018

Copy link
Copy Markdown
Contributor

ruby/ruby@989e07c features switching Range#=== to use internal r_cover_p
instead of rubyland include?. This breaks expected behavior of
ActiveSupport::CoreExt::Range documented since at least 8b67a02.

This patch adds overrides on Range#cover? and Range#=== and places all
three in a single module, CompareWithRange.
See failures at:
https://travis-ci.org/rails/rails/jobs/380939901#L1224-L1247

@rails-bot

Copy link
Copy Markdown

r? @kamipo

(@rails-bot has picked a reviewer for you, use r? to override)

@matthewd

Copy link
Copy Markdown
Member

If we go with this (see parallel discussion in #32945), I think we should also address cover?, and keep all three in the same file.

@utilum utilum force-pushed the range_case_equality branch 2 times, most recently from 9e6472e to 5104fb1 Compare May 21, 2018 16:38
@utilum

utilum commented May 21, 2018

Copy link
Copy Markdown
Contributor Author

Thank you both.

I've added cover? and moved all three into a single file, in module RangeCompareWithRange.

Better?

@utilum utilum force-pushed the range_case_equality branch from 5104fb1 to a26abf6 Compare May 21, 2018 16:51
@utilum

utilum commented May 21, 2018

Copy link
Copy Markdown
Contributor Author

PS: What do you think about moving overlaps? in with the others?

@utilum utilum changed the title Allow Range#=== on Range Allow Range#=== and Range#cover? on Range May 21, 2018
@utilum utilum force-pushed the range_case_equality branch 3 times, most recently from bf54f75 to 4e6dd71 Compare May 21, 2018 22:28

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range? -> cover?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! of course.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existence of this file is documented, and users may depend on it:

http://guides.rubyonrails.org/v5.2.0/active_support_core_extensions.html#include-questionmark

If we want to remove it, it needs a deprecation cycle first. Here's an example of how that might look:

https://github.com/rails/rails/blob/64c88fb5d2caf3c34742a07394ac68b8377c4936/activesupport/lib/active_support/core_ext/object/to_json.rb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Done.

@utilum utilum force-pushed the range_case_equality branch 5 times, most recently from 26f95f8 to a2e9e5d Compare May 22, 2018 05:23
Comment thread activesupport/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent detail for anyone interested in why the change was necessary, but the changelog should be a high level description of what changed from the user's perspective - it's probably sufficient to say that Range#cover? can now be given a range like Range#=== and Range#include?, and Range#=== works correctly when given a range on Ruby 2.6.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up. I hope I did not go too far by also removing the module name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the right call - users don't interact with the module directly, they just call the methods that it modifies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other file in Active Support that emits a deprecation requires active_support/deprecation first; we should do the same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://guides.rubyonrails.org/v5.2.0/api_documentation_guidelines.html#oxford-comma

Please use the Oxford comma ("red, white, and blue", instead of "red, white and blue").

🤓

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oxford in a comma, it's serious ;)

ruby/ruby@989e07c features switching `Range#===` to use internal `r_cover_p`
instead of rubyland `include?`. This breaks expected behavior of
`ActiveSupport::CoreExt::Range` documented since at least 8b67a02.

This patch adds overrides on `Range#cover?` and `Range#===` and places all
three in a single module, `CompareWithRange`.

*Requiring core_ext/range/include_range now causes a deprecation warnning*
@utilum utilum force-pushed the range_case_equality branch from a2e9e5d to fccf3ad Compare May 22, 2018 12:39
Comment thread activesupport/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a missing # in Range=== here.

Comment thread activesupport/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"warnning" -> "warning"

Can you also add active_support/ to the start of the filename, to match the example above?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're telling the user that requiring this file is deprecated, but not what they need to do instead - it's pretty easy to infer that they should now require active_support/core_ext/compare_range, but ideally we'd explicitly state that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right on.
Sorry about all the typos.

@eugeneius

Copy link
Copy Markdown
Member

What do you think about moving overlaps? in with the others?

I'd recommend leaving it where it is, mostly just to avoid inflicting the mild inconvenience of a deprecation warning on anyone cherry-picking that file on its own.

@utilum utilum force-pushed the range_case_equality branch from fccf3ad to 634f848 Compare May 22, 2018 13:19
Comment thread activesupport/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range#include -> Range#include?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread activesupport/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active_support_core_ext -> active_support/core_ext

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"now causes a deprecation warning" -> "is now deprecated"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread activesupport/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active_support/core_ext/compare_range -> active_support/core_ext/range/compare_range

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@utilum utilum force-pushed the range_case_equality branch from 634f848 to e04a79e Compare May 22, 2018 14:03
@rafaelfranca rafaelfranca merged commit fa9d01d into rails:master May 22, 2018
@utilum utilum deleted the range_case_equality branch May 22, 2018 20:56
yahonda pushed a commit to yahonda/rails that referenced this pull request Dec 24, 2018
Allow Range#=== and Range#cover? on Range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants