Skip to content

Instantly share code, notes, and snippets.

@davidrichards
Created November 10, 2011 08:33
Show Gist options
  • Save davidrichards/1354428 to your computer and use it in GitHub Desktop.
Save davidrichards/1354428 to your computer and use it in GitHub Desktop.
Recursive symbolize keys
require 'active_support/core_ext'
class Hash
def recursive_symbolize_keys!
symbolize_keys!
values.each do |h|
case h
when Array
h.each{|vv| vv.recursive_symbolize_keys! if Hash === vv }
when Hash
h.recursive_symbolize_keys!
end
end
self
end
end
@davidrichards
Copy link
Author

I've re-googled this one a few too many times. I'll remember where this is now. This is a cleanup/mix of several ideas found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment