Skip to content

Instantly share code, notes, and snippets.

@ollie
Last active December 11, 2015 05:09
Show Gist options
  • Save ollie/4550434 to your computer and use it in GitHub Desktop.
Save ollie/4550434 to your computer and use it in GitHub Desktop.
Ruby 1.9 Hash syntaxes
# Ruby 1.8 Hash syntax:
some_hash = { :person => 'John Doe', :age => 30 } # Hash-Rocket-style
# Ruby 1.9 Hash syntaxes:
some_hash = { :person => 'John Doe', :age => 30 } # Hash-Rocket-style syntax still there.
some_hash = { person: 'John Doe', age: 30 } # JSON-style syntax, keys are symbols behind the scenes.
# Watch out!
some_hash = { 'person' => 'John Doe', 'age' => 30 } # This will work.
some_hash = { 'person': 'John Doe', 'age': 30 } # This will not work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment