Issue #6118 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)


----------------------------------------
Feature #6118: Hash#keys_of(values), returns related keys of given values
https://bugs.ruby-lang.org/issues/6118#change-25399

Author: naruse (Yui NARUSE)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
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/