Answer the question
In order to leave comments, you need to log in
How to search by hash in Ruby?
For example, there is such a hash:
var = {
"aaa"=>{"age"=>11},
"bbb"=>{
"age"=>11,
"children"=>{
"child_1"=>{"age"=>11},
"child_2"=>{"age"=>11}
}
},
"ccc"=>{"age"=>11}
}
Answer the question
In order to leave comments, you need to log in
If the hash structure is known in advance and the location of child_2 does not change internally, then in Ruby 2.3+ you can simply do this:var.dig("bbb", "children", "child_1")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question