ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "ssuda (Sambasiva Suda)" <sambasivarao@gmail•com>
To: ruby-dev@ruby-lang.org (ruby developers list)
Subject: [ruby-dev:45439] [ruby-trunk - Feature #6118] Hash#keys_of(values), returns related keys of given values
Date: Tue, 27 Mar 2012 01:44:59 +0900	[thread overview]
Message-ID: <redmine.journal-25196.20120327014458@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-6118.20120306175507@ruby-lang.org


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/

  parent reply	other threads:[~2012-03-26 17:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-06  8:55 [ruby-dev:45310] [ruby-trunk - Feature #6118][Open] Hash#keys_of(values), returns related keys of given values Yui NARUSE
2012-03-26 16:38 ` [ruby-dev:45438] [ruby-trunk - Feature #6118] " ssuda (Sambasiva Suda)
2012-03-26 16:44 ` ssuda (Sambasiva Suda) [this message]
2012-03-29 16:54 ` [ruby-dev:45457] [ruby-trunk - Feature #6118][Assigned] " mame (Yusuke Endoh)
2012-11-20 13:18 ` [ruby-dev:46563] [ruby-trunk - Feature #6118] " mame (Yusuke Endoh)
2019-01-10  8:16 ` [ruby-dev:50758] [Ruby trunk Feature#6118][Feedback] " naruse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-25196.20120327014458@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).