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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.