var = {
"aaa"=>{"age"=>11},
"bbb"=>{
"age"=>11,
"children"=>{
"child_1"=>{"age"=>11},
"child_2"=>{"age"=>11}
}
},
"ccc"=>{"age"=>11}
}
class Hash
def find_all_values_for(key)
result = []
result << self[key]
self.values.each do |hash_value|
values = [hash_value] unless hash_value.is_a? Array
values.each do |value|
result += value.find_all_values_for(key) if value.is_a? Hash
end
end
result.compact
end
end