From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 6257917C6C12; Tue, 27 Mar 2012 02:02:21 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id C82E2EA6D7C; Tue, 27 Mar 2012 01:45:02 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id ED5A08FC29; Tue, 27 Mar 2012 01:45:04 +0900 (JST) X-Virus-Scanned: amavisd-new at funfun.nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by localhost (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rBWhJ-YGqh5C; Tue, 27 Mar 2012 01:45:04 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id C8D8B8FC28; Tue, 27 Mar 2012 01:45:04 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id CFF55952478; Tue, 27 Mar 2012 01:44:59 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 749AE3C21D3B6; Tue, 27 Mar 2012 01:44:59 +0900 (JST) Received: from fluorine.ruby-lang.org (www.rubyist.net [210.251.121.216]) by carbon.ruby-lang.org (Postfix) with ESMTP id 3E7833C21D397 for ; Tue, 27 Mar 2012 01:44:59 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id 2C9F93EE35 for ; Tue, 27 Mar 2012 01:44:59 +0900 (JST) Delivered-To: ruby-dev@ruby-lang.org Date: Tue, 27 Mar 2012 01:44:59 +0900 Posted: Tue, 27 Mar 2012 01:44:59 +0900 From: "ssuda (Sambasiva Suda)" Reply-To: ruby-dev@ruby-lang.org Subject: [ruby-dev:45439] [ruby-trunk - Feature #6118] Hash#keys_of(values), returns related keys of given values To: ruby-dev@ruby-lang.org (ruby developers list) Message-Id: References: X-ML-Name: ruby-dev X-Mail-Count: 45439 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-dev-ctl@ruby-lang.org; help= X-Mailer: Redmine X-Redmine-Issue-Author: naruse X-Auto-Response-Suppress: OOF X-Redmine-Issue-Id: 6118 X-Redmine-Mailinglistintegration-Message-Ids: 13664 X-Redmine-Project: ruby-trunk Auto-Submitted: auto-generated X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: bugs.ruby-lang.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Precedence: bulk List-Id: ruby-dev.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: Issue #6118 has been updated by ssuda (Sambasiva Suda). File 000_ruby_hash_keys_of.patch added Here is the updated patch ---------------------------------------- Feature #6118: Hash#keys_of(values), returns related keys of given values https://bugs.ruby-lang.org/issues/6118#change-25196 Author: naruse (Yui NARUSE) Status: Open Priority: Normal Assignee: Category: Target version: Hash#key(value) の複数版がほしいです。 {a: 1, b: 2, c: 3, d: 1}.key(1) => :a というメソッドはあるのですが、 {a: 1, b: 2, c: 3, d: 1}.keys_of(1) => [:a, :d] というメソッドは現状ありません。 Ruby での実装例は以下のような感じになります。 どうでしょうか。 class Hash def keys_of(*a) each_with_object([]) {|(k, v), r| r << k if a.include? v} end end -- http://bugs.ruby-lang.org/