lib/vagrant/data_store.rb
# Removes the "nil" and "empty?" values from the hash (children
# included) so that the final output JSON is cleaner.
Removes the "nil" and "empty?" values from the hash (children
included) so that the final output JSON is cleaner.
Removes the " nil " and " empty? " values from the hash ( children included ) so that the final output JSON is cleaner .
def clean_nil_and_empties(hash=self)
      hash.each do |k, v|
        clean_nil_and_empties(v) if v.is_a?(Hash)
      end
      bad_keys = hash.inject([]) do |acc, data|
        k,v = data
        acc.push(k) if v.nil?
        acc.push(k) if v.respond_to?(:empty?) && v.empty?
        acc
      end
      bad_keys.each do |key|
        hash.delete(key)
      end
    end
def clean_nil_and_empties ( hash = self ) hash . each do | k , v | clean_nil_and_empties ( v ) if v . is_a? ( Hash ) end bad_keys = hash . inject ( [ ] ) do | acc , data | k , v = data acc . push ( k ) if v . nil? acc . push ( k ) if v . respond_to? ( :empty? ) && v . empty? acc end bad_keys . each do | key | hash . delete ( key ) end end
Removes the "nil" and "empty?"
Removes the " nil " and " empty? "
# Clean depth first # Clean ourselves, knowing that any children have already been # cleaned up
hash
<not_specific>