Issue #6118 has been reported by Yui NARUSE. ---------------------------------------- Feature #6118: Hash#keys_of(values), returns related keys of given values https://bugs.ruby-lang.org/issues/6118 Author: 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
on 2012-03-06 09:55
on 2012-03-26 18:38
Issue #6118 has been updated by ssuda (Sambasiva Suda). File 000_ruby_hash_keys_of.patch added Here is the implementation for Hash#keys_of ---------------------------------------- Feature #6118: Hash#keys_of(values), returns related keys of given values https://bugs.ruby-lang.org/issues/6118#change-25194 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
on 2012-03-26 18:45
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
on 2012-03-29 18:54
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
on 2012-11-20 14:23
Issue #6118 has been updated by mame (Yusuke Endoh). Target version set to next minor ---------------------------------------- Feature #6118: Hash#keys_of(values), returns related keys of given values https://bugs.ruby-lang.org/issues/6118#change-33270 Author: naruse (Yui NARUSE) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: next minor 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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.