I have been trying to get rid of all hash keys in my YAML file that have empty (blank) values or empty hashes as values.
This earlier post helped me to get it almost
hash = {"x"=>{"m"=>{"n"=>{}}}, 'y' => 'content'} clean = proc{ |k,v| !v.empty? ? Hash === v ? v.delete_if(&clean) : false : true } hash.delete_if(&clean) #=> {"y"=>"content"}
or like @sawa suggested, you can use this proc
clean = proc{ |k,v| v.empty? or Hash === v && v.delete_if(&clean) }