Last active
December 11, 2015 05:09
-
-
Save ollie/4550434 to your computer and use it in GitHub Desktop.
Ruby 1.9 Hash syntaxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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