From: Fuad Saud Date: 2013-09-18T12:29:25-03:00 Subject: [ruby-core:57265] Re: [ruby-trunk - Feature #8921] Allow select, reject, etc to accept a regex --089e0163457236f39e04e6aa1a6b Content-Type: text/plain; charset=ISO-8859-1 Shouldn't select/reject use threequals? On Sep 18, 2013 12:25 PM, "kyledecot (Kyle Decot)" wrote: > > Issue #8921 has been updated by kyledecot (Kyle Decot). > > > =begin > Yes, grep would be a suitable alternative for `select` w/ a regex in this > instance. What about for `reject` though? I feel that > > %w[foo bar baz].reject /^ba/ # ["foo"] > > Is more readable than > > %w[foo bar baz].grep /^[^ba]/ # ["foo"] > > > Using `reject` also makes it so that I don't have to rewrite my regular > expression to negate what I'm looking for. My example is pretty trivial but > I think that it would quickly get out of hand if trying to grep things > "out" instead of "in". > =end > ---------------------------------------- > Feature #8921: Allow select, reject, etc to accept a regex > https://bugs.ruby-lang.org/issues/8921#change-41882 > > Author: kyledecot (Kyle Decot) > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > > > It would be really handy if for instance `select` could accept a regex. > For example > > ``` > %w[foo bar baz].select /^ba/ # ["bar", "baz"] > ``` > > I know that this is currently possible via the slightly longer syntax > > ``` > %w[foo bar baz].select{|i| i[/^ba/] } # ["bar", "baz"] > ``` > > > > -- > http://bugs.ruby-lang.org/ > --089e0163457236f39e04e6aa1a6b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Shouldn't select/reject use threequals?

On Sep 18, 2013 12:25 PM, "kyledecot (Kyle = Decot)" <kyle.decot@icloud= .com> wrote:

Issue #8921 has been updated by kyledecot (Kyle Decot).


=3Dbegin
Yes, grep would be a suitable alternative for `select` w/ a regex in this i= nstance. What about for `reject` though? I feel that

=A0 =A0 %w[foo bar baz].reject /^ba/ # ["foo"]

Is more readable than

=A0 =A0 %w[foo bar baz].grep /^[^ba]/ # ["foo"]


Using `reject` also makes it so that I don't have to rewrite my regular= expression to negate what I'm looking for. My example is pretty trivia= l but I think that it would quickly get out of hand if trying to grep thing= s "out" instead of "in".
=3Dend
----------------------------------------
Feature #8921: Allow select, reject, etc to accept a regex
https://bugs.ruby-lang.org/issues/8921#change-41882

Author: kyledecot (Kyle Decot)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


It would be really handy if for instance `select` could accept a regex. For= example

```
%w[foo bar baz].select /^ba/ # ["bar", "baz"]
```

I know that this is currently possible via the slightly longer syntax

```
%w[foo bar baz].select{|i| i[/^ba/] } # ["bar", "baz"]<= br> ```



--
http://bugs.ruby-l= ang.org/
--089e0163457236f39e04e6aa1a6b--