Skip to content

Instantly share code, notes, and snippets.

@localshred
Created August 9, 2012 17:56
Show Gist options
  • Save localshred/3306542 to your computer and use it in GitHub Desktop.
Save localshred/3306542 to your computer and use it in GitHub Desktop.
Symbolize keys doesn't do what I expected when to_sym equivalent keys exist.
# Fascinating behavior of symbolize_keys usage. If you have two keys that
# are `to_sym` equivalents, the non-symbol version is the winner,
# regardless of the order in the hash.
# For some reason I expected if a symbol key existed it would be
# the winner.
1.9.2p290 :002 > {"one" => 1, :one => 2}.symbolize_keys
=> {:one=>1}
1.9.2p290 :001 > {:one => 1, "one" => 2}.symbolize_keys
=> {:one=>2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment