Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Created May 2, 2016 12:26
Show Gist options
  • Save YumaInaura/6f84f246a373f0e913a26715820878d2 to your computer and use it in GitHub Desktop.
Save YumaInaura/6f84f246a373f0e913a26715820878d2 to your computer and use it in GitHub Desktop.
Rails | ハッシュのキーを全てシンボルから文字列に変える ( stringify_keys / deep_stringify_keys ) ref: http://qiita.com/Yinaura/items/4d999e0ee6b450f25ae7
{ a: 1, b: 2, c: 3 }.stringify_keys
# => {"a"=>1, "b"=>2, "c"=>3}
{ a: 1, b: 2, c: { d: 3 } }.deep_stringify_keys
# => {"a"=>1, "b"=>2, "c"=>{"d"=>3}}
{ a:1, b: 2, c: [ { d: [ { e:3 } ] } ] }.deep_stringify_keys
# => {"a"=>1, "b"=>2, "c"=>[{"d"=>[{"e"=>3}]}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment