From: Clay Trump Date: 2012-08-10T02:29:58+09:00 Subject: [ruby-core:47093] Re: [ruby-trunk - Feature #6847][Open] Hash#extract --14dae9340fc782347c04c6d89313 Content-Type: text/plain; charset=ISO-8859-1 Isn't that like the method slice in ActiveSupport? On Thu, Aug 9, 2012 at 1:01 PM, citizen428 (Michael Kohl) < citizen428@gmail.com> wrote: > > Issue #6847 has been reported by citizen428 (Michael Kohl). > > ---------------------------------------- > Feature #6847: Hash#extract > https://bugs.ruby-lang.org/issues/6847 > > Author: citizen428 (Michael Kohl) > Status: Open > Priority: Normal > Assignee: > Category: core > Target version: > > > I often need a method to extract "subhashes" from hashes. I often > monkey-patched this into hash and found "extract" to be a good name for the > method. Afterwards I found out that there actually is a mutating method > called "extract!" in ActiveSupport, so I guess the name is kinda > established. Here's the Ruby version from my private extension library, if > there's any interest in this I would try to re-implement it in C: > > class Hash > def extract(*ks) > existing = keys & ks > Hash[existing.zip(values_at(*existing))] > end > end > > > -- > http://bugs.ruby-lang.org/ > > -- --14dae9340fc782347c04c6d89313 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Isn't that like the method slice in ActiveSupport?

On Thu, Aug 9, 2012 at 1:01 PM, citizen428 (Michael Kohl) <citizen428@gmail.com> wrote:

Issue #6847 has been reported by citizen428 (Michael Kohl).

----------------------------------------
Feature #6847: Hash#extract
https:= //bugs.ruby-lang.org/issues/6847

Author: citizen428 (Michael Kohl)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:


I often need a method to extract "subhashes" from hashes. I often= monkey-patched this into hash and found "extract" to be a good n= ame for the method. Afterwards I found out that there actually is a mutatin= g method called "extract!" in ActiveSupport, so I guess the name = is kinda established. Here's the Ruby version from my private extension= library, if there's any interest in this I would try to re-implement i= t in C:

class Hash
=A0 def extract(*ks)
=A0 =A0 existing =3D keys & ks
=A0 =A0 Hash[existing.zip(values_at(*existing))]
=A0 end
end


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




--
<lay t= rum/>

--14dae9340fc782347c04c6d89313--