How do I find keys in my hash to map to elements that match a condition?

后端 未结 3 1615
北荒
北荒 2021-01-27 20:58

I have a hash that maps integers to arrays. For example

{1 => [\"abc\"], 2 => [\"ccc\", \"ffffd\"]}

How do I get all the keys from my hash

3条回答
  •  深忆病人
    2021-01-27 21:50

    {1 => ["abc"], 2 => ["ccc", "ffffd"]}.select{|_, a| a.length > 1}.keys
    # => [2]
    

提交回复
热议问题