Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/ext/hash.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.convert_keys_to_strings(hash) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ext/hash.rb', line 13 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 |
Instance Method Details
#convert_keys_to_strings ⇒ Object
8 9 10 11 |
# File 'lib/ext/hash.rb', line 8 def convert_keys_to_strings Hash.convert_keys_to_strings(self) self end |
#remove_nils ⇒ Object
3 4 5 6 |
# File 'lib/ext/hash.rb', line 3 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 |