Sha256: 52dd25d4d7fb26b78680c29a4ba98db26f8cf2b8dcfeda9a742b89033f859175

Contents?: true

Size: 429 Bytes

Versions: 1

Compression:

Stored size: 429 Bytes

Contents

class Hash
  # Deletes all key/value pairs where the value is empty string/array/hash or nil.
  def delete_blank
    delete_if do |_, v|
      (v.blank? && v != false)
    end
  end

  # Recursively deletes all key/value pairs where the value is empty string/array/hash or nil.
  def deep_delete_blank
    delete_if do |_, v|
      (v.blank? && v != false) || v.instance_of?(Hash) && v.deep_delete_blank.empty?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inactive_support-1.1.0 lib/inactive_support/hash/delete_blank.rb