On 24 November 2010 17:47, Roger Pack <redmine / ruby-lang.org> wrote:
> Feature #4086: Feature request: add String#contain? and {Enumerable,Array=
}#contain? methods
>
> Currently Strings and Enumerables have a contain? method for searching fo=
r if one includes another.

You probably meant "have an include? method"

> I tend to "reach for" an include? method for the same, since it makes mor=
e sense in my head. =A0For instance "is this string included in that one? D=
oes this array include this member?"

There is already #include?, I guess you meant #contain?

Your sentence I just quoted feels right enough to me to not want anything e=
lse:
"is this string included in that one? Does this array include this member?"

Especially about Arrays, I prefer #include?

if ary.include? element
if ary.contain? element

However, you might be right, #include? is not the best name for string
inclusion in another.

I would expect String#include? to say me if a single character is part
of the String, because the set of characters is likely the only
enumerable part of a String which make sense here.

But, as we all know, characters in Ruby happen to be String of length
1, and then the current #include? behavior is logical.

#contain? might fit better for substring inclusion, but the
'cleverness' of #include? is nicer to me.

> Since ruby is typically not averse to several ways to do the same thing (=
example: Array#{detect,find}, Array#{collect,map} etc.)

I personally disagree to this, such basic methods duplicated seems bad
design for readers. I like TMTOWTDI, but this is just confusing.

Just an opinion,
Benoit Daloze