Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7501 (closed enhancement: undocumented)

Opened 1 year ago

Last modified 10 months ago

[PATCH] Array.select allows regex

Reported by: nicwilliams Assigned to: core
Priority: normal Milestone: 1.2.4
Component: ActiveSupport Version: edge
Severity: minor Keywords: tiny
Cc:

Description

Previously, to select from an array using a regex, you needed:

['aaa','bbb','baa'].select {|w| w =~ /aa/}
=> ["aaa", "baa"]

Now, you get the much simpler:

>> ['aaa','bbb','baa'].select /aa/
=> ["aaa", "baa"]

TEST CASES: Included.

NOTE: core_ext.rb is modified to load core_ext/module.rb first, so alias_method_chain is available

Attachments

select_with_regex.patch (3.0 kB) - added by nicwilliams on 02/07/07 03:09:57.
Select with regex - Code and tests

Change History

02/07/07 03:09:57 changed by nicwilliams

  • attachment select_with_regex.patch added.

Select with regex - Code and tests

02/07/07 03:28:07 changed by nicwilliams

I've since been pointed to Array.grep as doing the same thing; but I really think select is a more common API starting point, and should support passing a Regexpr as a parameter.

02/11/07 02:17:19 changed by dcmanges

Developers should just use Enumerable#grep. Also, without documentation nobody will know that using select with a regexp is available.

02/24/07 18:49:00 changed by josh

  • keywords set to verified tiny.

06/23/07 14:37:11 changed by nicwilliams

I agree with #grep, though #select(regex) is still nice.

07/05/07 07:49:20 changed by nicwilliams

If I add docco will this be worth adding to core? or reject ticket?

07/19/07 23:58:11 changed by mpalmer

  • keywords changed from verified tiny to tiny.
  • status changed from new to closed.
  • resolution set to undocumented.

I'd say use #grep myself, but at the very least this needs docs and some points. As per http://wiki.rubyonrails.org/rails/pages/PatchRequirements and http://dev.rubyonrails.org/, if you still want this patch in, please add documentation, reopen the ticket, and hunt for seconders.