add Enumerable#exclude? antonym
Please add Enumerable#exclude? as antonym of Enumerable#include?
This allows me to construct Boolean expressions more pleasantly:
if File.exist? some_file and not some_list.include? some_file
Can be written as:
if File.exist? some_file and some_list.exclude? some_file
Thanks for your consideration.
#4 [ruby-core:43828] Updated by Suraj Kurapati about 4 years ago
I didn't ask for antonmys for all predicates; only for #exclude?.
The reason for #exclude? is for more "natural" boolean expressions:
if File.exist? some_file and some_list.exclude? some_file if File.exist? some_file and not some_list.include? some_file
That "not SOMETHING.include? SOMETHING" pattern appears often in my code, so that's why I created this request. Of course, me saying "appears often" does not constitute as solid evidence in support of adding #exclude? so I have no choice but to accept your judgement on this request. It's your call.
Thanks for your consideration.
#6 [ruby-core:43843] Updated by Nikolai Weibull about 4 years ago
On Thu, Mar 29, 2012 at 01:26, sunaku (Suraj Kurapati) email@example.com wrote:
Issue #5644 has been updated by sunaku (Suraj Kurapati).
The reason for #exclude? is for more "natural" boolean expressions
I don’t think #exclude? really conveys what’s being done very well.
Yes, “exclude” is the antonym of “include”, but the meaning of %[a b
c].include? x is very natural, whereas %[a b c].exclude? x isn’t.
Does it mean that %[a b c] contains the elements that should be
excluded and is x among them, or is x not included among the elements
of %[a b c]?
#9 [ruby-core:43940] Updated by Rodrigo Rosenfeld Rosas about 4 years ago
I think I've misunderstood the question posed by Nikolai. I've just read it again but I think that the other meaning presented by him doesn't make any sense. "does the array contain the elements that should be excluded?". Really? I read this like in English:
Does [1, 3, 5] exclude 4?
Ask someone that doesn't know anything about programming and see what will she answer to this question.
#11 [ruby-core:43942] Updated by Thomas Sawyer about 4 years ago
There really is no better term b/c all such terms are going to have the same connotations.
As with "include" if you add an "s" to the word then it reads more like typical English, i.e. "a excludes b ?". To use the singular form you have to add a modal verb like "does a exclude b ?" Which makes it easy to see that this is the right meaning.
#12 [ruby-core:43949] Updated by Nikolai Weibull about 4 years ago
On Fri, Mar 30, 2012 at 16:02, matz (Yukihiro Matsumoto)
OK, you think negative for include? is special. Understood.
But as Nikolai pointed out, exclude? is not the best name for the function.
How about changing the definition of Enumerable#none?, #any?, and
#all? to take an optional argument that is compared against each
element using #==. Then we have
if File.exist? some_file and some_list.none? some_file
I would not write it like that – I’d still use not a.include? b, which
I think is hard to beat – but then we at least don’t need to come up
with a new name and these three methods gain semantics that I’ve felt
they were lacking.