The hash code example

Let's start by creating a hash:

positions = {                 first_base: "Chris Carter",                 second_base: "Jose Altuve",                 short_stop: "Carlos Correa"             } 

When you run this code, you can see the hash, where the keys are mapped to their respective values:

In the written code, I placed each key/value pair on their own line for readability purposes; however, you can also use the irb console and build the hash on a single line. This is an important item to know because the Ruby parser doesn't care about white spaces, so both options will work fine. However, when you're building code-based programs it's considered a best practice to place each ...

Get Comprehensive Ruby Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.