Ho una matrice di hash, @fathers.Come faccio a cercare all'interno di un array di hash per valori hash in 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
Come posso cercare questo array e restituire un array di hash per il quale un blocco restituisce true?
Ad esempio:
@fathers.some_method("age" > 35) #=> array containing the hashes of bob and batman
Grazie.
Oh! Eri il primo! Cancellando la mia risposta e +1. –
Eccellente. Grazie molto! – doctororange
Come nota, se si voleva trovare solo uno (il primo) si può usare '@fathers.find {| padre | padre ["età"]> 35} 'invece. –