相关疑难解决方法(0)

如何在ruby中通过哈希值在哈希数组中进行搜索?

我有一系列哈希,@ fathers.

a_father = { "father" => "Bob", "age" =>  40 }
@fathers << a_father
a_father = { "father" => "David", "age" =>  32 }
@fathers << a_father
a_father = { "father" => "Batman", "age" =>  50 }
@fathers << a_father 
Run Code Online (Sandbox Code Playgroud)

如何搜索此数组并返回一个块返回true的哈希数组?

例如:

@fathers.some_method("age" > 35) #=> array containing the hashes of bob and batman
Run Code Online (Sandbox Code Playgroud)

谢谢.

ruby arrays hash search

227
推荐指数
4
解决办法
16万
查看次数

标签 统计

arrays ×1

hash ×1

ruby ×1

search ×1