Intern Track Roadmap

Ruby collections: hashes

This course covers Ruby hashes, which store each value under a key instead of a position. It starts with the symbol shorthand and the hash rocket syntax, reading values with [] and the difference between symbol and string keys. It then covers adding, updating and removing entries, checking keys and values with key?, value? and fetch, and getting keys and values in insertion order. The last lessons cover merge and merge!, nested hashes with dig, and a small order summary challenge that combines these methods.

What you'll learn

  • ✓Creating hashes with the symbol shorthand or the hash rocket syntax
  • ✓Adding, updating and removing keys, and how hashes mutate in place
  • ✓Choosing between [], fetch and key? for lookups
  • ✓Reading keys and values in guaranteed insertion order
  • ✓Combining hashes with merge, merge! and a conflict block
  • ✓Reading nested hashes and arrays safely with dig
Free preview · Lesson 1 2 min read

Creating and accessing hashes

Arrays store values by position, like fruits[0] for the first one. A hash stores each value under a name, a key, and looks it up by that name.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...