I am trying to get rid of all hash keys in my YAML file that have empty (empty) values ββor empty hashes as values.
This earlier post helped me get it almost right, but the recursive single-line layer leaves my YAML dump with empty hashes when there is enough deep nesting.
I would really appreciate any help on this. Thanks!
proc = Proc.new { |k, v| (v.kind_of?(Hash) && !v.empty? ) ? (v.delete_if(&proc); nil) : v.blank? } hash = {"x"=>{"m"=>{"n"=>{}}}, 'y' => 'content'} hash.delete_if(&proc)
Actual output
{"x"=>{"m"=>{}}, "y"=>"content"}
Required conclusion
{"y"=>"content"}
ruby ruby-on-rails yaml hash
juwalter
source share