Created
September 24, 2012 12:20
-
-
Save tekei/3775681 to your computer and use it in GitHub Desktop.
ネストしたArray, Hashに対する stringify_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' | |
Array.class_eval do | |
def stringify_keys | |
map { |v| v.respond_to?('stringify_keys') ? v.stringify_keys : v } | |
end | |
end | |
Hash.class_eval do | |
alias :old_stringify_keys :stringify_keys | |
def stringify_keys | |
result = old_stringify_keys | |
result.each { |k, v| result[k] = (v.respond_to?('stringify_keys') ? v.stringify_keys : v) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment