Actions
Misc #18352
openWhat is the Hash#grep expected?
Status:
Open
Assignee:
-
Description
Current ruby implement, When use Array#grep, the method name means is expected.
[19] pry(#<App>)> [:foo1, :foo2, :bar].grep /foo/
[
:foo1,
:foo2
]
But when use with hash, the result is really confusing ...
[12] pry(#<App>)> {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)
[20] pry(#<App>)> {foo1: '100', foo2: '200', bar: '200'}.grep /foo/
{
:foo1 => "100",
:foo2 => "200"
}
Actions
Like0
Like0Like0