我该如何从嵌套的哈希或 YAML 文件中删除所有空元素(空列表项)?
hash = { a: true, b: false, c: nil }
=> {:a=>true, :b=>false, :c=>nil}
hash.inject({}){|c, (k, v)| c[k] = v unless v.nil?; c}
=> {:a=>true, :b=>false}
validated_params
.to_h
.delete_if {|_,v| !v.present? }
hash.compact!
- courtsimas