Posted By

viatropos on 08/11/10


Tagged

ruby hash symbol


Versions (?)

Recursively Symbolize Keys in Ruby


 / Published in: Ruby
 

URL: recursively-symbolize-keys-in-ruby

  1. class Hash
  2. def recursively_symbolize_keys!
  3. self.symbolize_keys!
  4. self.values.each do |v|
  5. if v.is_a? Hash
  6. v.recursively_symbolize_keys!
  7. elsif v.is_a? Array
  8. v.recursively_symbolize_keys!
  9. end
  10. end
  11. self
  12. end
  13. end
  14.  
  15. class Array
  16. def recursively_symbolize_keys!
  17. self.each do |item|
  18. if item.is_a? Hash
  19. item.recursively_symbolize_keys!
  20. elsif item.is_a? Array
  21. item.recursively_symbolize_keys!
  22. end
  23. end
  24. end
  25. end

Report this snippet  

You need to login to post a comment.