Great article, thanks for that.
You probably already know that, but you can also write Ruby hashes in a similar notation to Python dictionaries:
# Ruby hash hex_colors = { white: '#FFFFFF', grey_light: '#CCCCCC', grey_dark: '#333333', black: '#000000' } puts(hex_colors[:black]) # #000000
Some caveats when using this notation though:
# invalid Ruby hash numbers = { 1: 'one', 2: 'two', 3: 'three'} # valid Ruby hash (no need to use quotes) numbers = { one: 1, two: 2, three: 3}
hex_colors = { white: '#FFFFFF', grey_light: '#CCCCCC', grey_dark: '#333333', black: '#000000' } # valid notation to fetch values hex_colors[:black] # returns #000000 # invalid notation to fetch values hex_colors['black'] # returns nil
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article, thanks for that.
You probably already know that, but you can also write Ruby hashes in a similar notation to Python dictionaries:
Some caveats when using this notation though: