Sha256: a6b5639ad3b046c290f228c0298bf5090d302143f383536cefeb6dca5065a284

Contents?: true

Size: 648 Bytes

Versions: 13

Compression:

Stored size: 648 Bytes

Contents

class Hash

  def remove_nils
    clear_nils = Proc.new { |k, v| v.kind_of?(Hash) ? (v.delete_if(&clear_nils); nil) : v.nil? }; 
    self.delete_if(&clear_nils)
  end

  def convert_keys_to_strings
     Hash.convert_keys_to_strings(self)
     self
  end

  def self.convert_keys_to_strings(hash)
     if hash.kind_of? Hash 
         hash.keys.each do |k|
          v = hash[k]
          if k.kind_of? Symbol
            hash[k.to_s] = hash[k]
            hash.delete(k)
          end
          Hash.convert_keys_to_strings(v)
       end
     elsif hash.kind_of? Array 
       hash.each{|val| Hash.convert_keys_to_strings(val)}
     end 
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bonnie_bundler-3.0.0 lib/ext/hash.rb
bonnie_bundler-2.2.5 lib/ext/hash.rb
bonnie_bundler-2.2.4 lib/ext/hash.rb
bonnie_bundler-2.2.3 lib/ext/hash.rb
bonnie_bundler-2.2.1 lib/ext/hash.rb
bonnie_bundler-2.2.0 lib/ext/hash.rb
bonnie_bundler-2.1.2 lib/ext/hash.rb
bonnie_bundler-2.1.1 lib/ext/hash.rb
bonnie_bundler-2.1.0 lib/ext/hash.rb
bonnie_bundler-2.0.3 lib/ext/hash.rb
bonnie_bundler-2.0.2 lib/ext/hash.rb
bonnie_bundler-2.0.1 lib/ext/hash.rb
bonnie_bundler-2.0.0 lib/ext/hash.rb