From: "citizen428 (Michael Kohl)" Date: 2012-08-11T18:42:36+09:00 Subject: [ruby-core:47126] [ruby-trunk - Feature #6847] Hash#extract Issue #6847 has been updated by citizen428 (Michael Kohl). claytrump (Clay Trump) wrote: > Isn't that like the method slice in ActiveSupport? It's definitely like extract! in ActiveSupport, just non-destructive. I still think this is useful enough to be in core though. I needed it repeatedly, I know other people who regularly monkey-patch it into Hash and not everyone wants to drag ActiveSupport into their non-Rails projects. I don't insist on it of course, but it wouldn't be the first thing to make it from an extensions library into core, think of Symbol#to_proc for example. ---------------------------------------- Feature #6847: Hash#extract https://bugs.ruby-lang.org/issues/6847#change-28781 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/