Created
November 10, 2011 08:33
-
-
Save davidrichards/1354428 to your computer and use it in GitHub Desktop.
Recursive symbolize keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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