Skip to content

Instantly share code, notes, and snippets.

@saxxi
Created January 25, 2011 14:08
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 saxxi/794951 to your computer and use it in GitHub Desktop.
Save saxxi/794951 to your computer and use it in GitHub Desktop.
convert hash object to symbol
# a = {"three"=>3, "two"=>2, "one"=>1}.symbolize_keys = {:three=>3, :one=>1, :two=>2}
# from Greg => http://objectmix.com/ruby/325092-transform-hash-key-string-into-symbol.html
class Hash
def symbolize_keys
replace(inject({}) { |h,(k,v)| h[k.to_sym] = v; h })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment