From: "matheusrich (Matheus Richard)" Date: 2021-11-28T22:39:21+00:00 Subject: [ruby-core:106304] [Ruby master Misc#18352] What is the Hash#grep expected? Issue #18352 has been updated by matheusrich (Matheus Richard). Should we have `grep_{keys,values}`? ---------------------------------------- Misc #18352: What is the Hash#grep expected? https://bugs.ruby-lang.org/issues/18352#change-94930 * Author: zw963 (Wei Zheng) * Status: Open * Priority: Normal ---------------------------------------- Current ruby implement, When use Array#grep, the method name means is expected. ``` [19] pry(#)> [:foo1, :foo2, :bar].grep /foo/ [ :foo1, :foo2 ] ``` But when use with hash, the result is really confusing ... ```rb [12] pry(#)> {foo: '100', bar: '200'}.grep /foo/ [] ``` This result almost make Include Enumerable#grep into Hash is totally meaningless, right? so, i consider if we should introduce a `Hash#grep` method instead. Following is what is expected. (=== is matching on hash key, as Hash#slice) ```rb [20] pry(#)> {foo1: '100', foo2: '200', bar: '200'}.grep /foo/ { :foo1 => "100", :foo2 => "200" } ``` -- https://bugs.ruby-lang.org/ Unsubscribe: