-
Notifications
You must be signed in to change notification settings - Fork 22.1k
Adds not_in? onto Object
#25914
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
Adds not_in? onto Object
#25914
Conversation
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @matthewd (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
|
Thank you for the pull request but we avoid to add new core extensions in Active Support unless they are going to be used in the framework or in a large number of applications. In this specific case, both |
|
@rafaelfranca We have Why not make lives a little better for Rails devs with this simple patch? |
|
Because in my opinion the core_ext of Active Support is already huge and I'd love to have things in Ruby itself not Rails. I'm fine with adding this to Rails, but it should be proposed to ruby too. If you believe it is that useful, it should be in the language. |
|
@rafaelfranca Is that what you're planning to do with |
Seems like a reasonable compromise. I agree it should be in core. I can tackle that later and then reverse this? |
|
We are taking that direction, yes. We never proposed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✂️ this blank line.
I don't mind doing it, but you probably have more experience proposing to Ruby core than I do. Happy to help if you need me. |
|
@rafaelfranca Not sure what's up with those Travis failures. They look systemic. Any ideas? |
|
Yeah, it were broken on master, but already fixed. |
|
Thank you for the pull request! |
|
@rafaelfranca Thanks for merging and for re-considering! |
|
"exclude?" is a nicer phrasing, for some uses, vs "not include?"; "not_in?" does not have the same merit over "not in?". |
|
@matthewd I don't follow. "not in" in the verbal (and logical opposite of) "in". Are you suggesting another phrase instead? |
|
@jmccartie my point is that ruby already has a perfectly satisfactory way of writing "not". The natural language opposite of "include" is "exclude", whereas, as you say, the natural language opposite of "in" is "not in" -- we don't need a new method for that, because that's exactly how I don't see any argument for this that wouldn't equally apply to a similar opposing method for every other |
|
@matthewd Yup, I completely get your point. And I certainly wouldn't propose we create opposites for every However, the original purpose of And I agree with Rafael -- I'd love to see these methods (including Rails' Cheers, |
I still haven't seen an argument that doesn't work just as well for Perhaps you'd be better served by suggesting a syntax extension upstream, such that |
|
I'd love to have a method for this, but You can read the long history of rejecting not_in? in #258, #12912, and #265. |
|
@dhh Very sad to see this get discussed, merged, then thrown away because of "history".
For the record, this comment explains it perfectly. |
|
This isn't because of "history" but because of all the reasons examined in those prior PRs. From my perspective, there's no new information or arguments that we didn't already consider at length in 2011 and 2013, as per the referenced tickets. Thankfully, Ruby and Rails make it oh-so-easy to include a method like So please do have at it in your own project, and do return with a new PR if you get an epiphany on naming that was not previously considered. I like the functionality, but until there is a great name for it, I'd rather live without. (This principle of waiting for the right name, and rejecting features until we find them, has a long tradition in Ruby core development as well. One that I'd happy to continue). |
|
@dhh I humbly disagree. And I wish this could get discussed again. But... I very much appreciate you taking the time to provide a lengthy response. Cheers. 🍻 |
|
I believe the term you're looking for is "exclusive". |
|
@nickpoorman For this behavior? No, I disagree. "not in" is typically used in English here. For example:
"exclusive" and "ex?" (as suggested in the other PR's) does not fit here, in my opinion. |
|
|
|
I don't want to open a new issue about it but I do want to give my 2 cents on it, even though it's a super old thread (sorry ..) I have this code I want to refactor: I want to make it: In this example, since the safe navigation operator is used, Granted, I could simply add it to our codebase, but I like to avoid too many core patches. |
|
@maxp-edcast We've gone over this a lot of times over the years. I respect this is something people are eager to have, but I haven't changed my opinion given that there's no new information available. You can write your example like: if !params[:status]&.in?(User::PERMITTED_STATUSES)Or unless params[:status]&.in?(User::PERMITTED_STATUSES) |
|
@dhh thanks for reading and responding. The examples you give are not the same as mine ( |
|
Ah! All the more reason to write it in a less confusing way, then. Combine the try and the not is a pretty subtle read. I think the first example you had with an explicit present check is preferable. |
|
It is may will to broke codebase which contain |
|
I personally feel that is far less readable than There is less mental load to remember the context of the operator. That's exactly why all the languages have I regret that this has to be a method though. On this regard I prefer the (syntactic) choice of Python that features two infix operators, |
Introduce
not_in?onObject.As an opposite method for
in?,not_in?provides equivalent support for exclusion. This turns this:...into this: