Sha256: 46a87e61b868ad6d1c6cc70807fdc03cdefe5572f3178a586d556505b46590d1
Contents?: true
Size: 565 Bytes
Versions: 1
Compression:
Stored size: 565 Bytes
Contents
class Hash # Remove nil values def compact self.dup.compact! end # Remove nil values - !desctructively! def compact! delete_if{|k,v| v.nil?} end def compact_blank self.dup.compact_blank! end def compact_blank! delete_if{|k,v| v.blank?} end def recursive_compact_blank! delete_if do |k,v| if v.is_a?(Hash) v.recursive_compact_blank! v.recursive_blank? elsif v.is_a?(Array) v.recursive_compact_blank! v.recursive_blank? else v.blank? end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby_core_extensions-0.0.1 | lib/ruby_core_extensions/compact/hash.rb |