Skip to content

Instantly share code, notes, and snippets.

@sandinist
Created April 19, 2012 06:02
Show Gist options
  • Save sandinist/2419008 to your computer and use it in GitHub Desktop.
Save sandinist/2419008 to your computer and use it in GitHub Desktop.
Change the key to Hashes in the Array from string to symbol.
src = [{"a"=>"aaa", "b"=>"bbb"}, {"c"=>"ccc"}]
src.map{|x| x.each_with_object({}) {|(k, v), h| h[k.to_sym] = v}}
#=> [{:a=>"aaa", :b=>"bbb"}, {:c=>"ccc"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment