Skip to content

Instantly share code, notes, and snippets.

@lucasdavila
Created October 15, 2012 13:01
Show Gist options
  • Save lucasdavila/3892347 to your computer and use it in GitHub Desktop.
Save lucasdavila/3892347 to your computer and use it in GitHub Desktop.
Merge itself with simbolized keys in rails
hash = {'a' => 1, 'b' => 2}
# => {"a"=>1, "b"=>2}
hash.merge hash.symbolize_keys
# => {"a"=>1, "b"=>2, :a=>1, :b=>2}
hash.to_json
# => "{\"a\":1,\"b\":2}"
hash[:a] = 3
hash["b"] = 4
hash
# => {"a"=>1, "b"=>4, :a=>3, :b=>2}
hash.to_json
# => "{\"a\":3,\"b\":2}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment