Skip to content

Instantly share code, notes, and snippets.

@tekei
Created September 24, 2012 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekei/3775681 to your computer and use it in GitHub Desktop.
Save tekei/3775681 to your computer and use it in GitHub Desktop.
ネストした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