Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ネストしたArray, Hashに対する stringify_keys
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