Find a spice jar
Before you start this beginner track
Variables, arrays, and key-value data. Collection blocks are a step beyond basic syntax.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Predict the result.
What two lines does the spice lookup print?
spices = { cumin: "warm", mint: "cool" }note = spices.fetch(:saffron, "unlisted")puts noteputs spices.lengthEach mission is an independent Ruby 3 or later script. Save as quest.rb and run ruby quest.rb. All methods are built into Ruby; no gems or external data are needed.
Review the lesson
A kitchen notebook stores tasting notes in a hash with symbol keys. fetch returns the value for a key, or its supplied fallback when that key is missing. Unlike assigning a missing entry, fetching does not change the notebook. length therefore still reports the original number of stored spices.