Tengo una variedad de hashes, @fathers.¿Cómo busco dentro de una matriz de valores hash por valores de hash en ruby?
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
¿Cómo puedo buscar esta matriz y devolver una matriz de valores hash para los que un bloque devuelve verdadero?
Por ejemplo:
@fathers.some_method("age" > 35) #=> array containing the hashes of bob and batman
Gracias.
Oh! ¡Tú fuiste el primero! Borrando mi respuesta y +1. –
Excelente. ¡Muchas gracias! – doctororange
Como nota, si solo quiere encontrar una sola (la primera) puede usar '@fathers.find {| father | padre ["edad"]> 35} 'en su lugar. –