Sha256: 77a76063be9c22e3d2fd9b1a76c07bc246225a4d62e7e5c1a3b33f256365edbd
Contents?: true
Size: 529 Bytes
Versions: 2
Compression:
Stored size: 529 Bytes
Contents
require 'gorillib/object/blank' # # deep_compact! removes all keys with 'blank?' values in the hash, in place, recursively # class Hash def deep_compact! self.each do |key, val| case val when Hash val = val.deep_compact! self.delete(key) if val.blank? when Array val = val.deep_compact! self.delete(key) if val.blank? when String self.delete(key) if val.blank? when nil self.delete(key) end end self.blank? ? nil : self end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gorillib-0.0.7 | lib/gorillib/hash/deep_compact.rb |
gorillib-0.0.6 | lib/gorillib/hash/deep_compact.rb |