A hash stores pairs: every key points to exactly one value. You look things up by name, not by position.
1 Key → value
A hash maps keys to values: { name: "Asha", level: 7 }.
2 Symbol keys
The shorthand name: creates the Symbol :name — the classic Ruby hash style.
3 Instant lookup
hero[:level] jumps straight to its value — no scanning, no indexes.
4 Missing keys give nil
Look up a key that is not there and you get nil — not an error.
Label your data
Key → value1A hash maps keys to values: { name: "Asha", level: 7 }. Symbol keys2The shorthand name: creates the Symbol :name — the classic Ruby hash style. Instant lookup3hero[:level] jumps straight to its value — no scanning, no indexes. Missing keys give nil4Look up a key that is not there and you get nil — not an error. 4 building blocks make up Label your data
hero[:hp] looks instant — here is the journey the hash makes for you.
Create pairs, add one mid-script, then ask for keys and the length.
mainhero starts with two pairs — symbol keys on the left, values on the right.
Memory
hero= {:name=>"Asha", :level=>7}
Console
output appears as the program runs…
Click an expression, then click what it does to lock the pair.
6 conceptsTap a card to expand ?{ name: "Ada" }drops into place
?hero[:level]drops into place
?hero[:hp] = 100drops into place
?keysdrops into place
?valuesdrops into place
?nildrops into place
One new key, one overwritten key, one missing key — four lines of truth.
Your predicted output — one line per console line
Hint: Assigning to :tea overwrites the old 3. The final lookup is a key that was never added: it gives nil, and puts nil prints an empty line.
01Hashes map keys to values — symbol keys are the Ruby default style.
02hero[:hp] = 100 adds a pair, or overwrites one that already exists.
03Lookups are direct: hash the key, jump to its bucket, return the value.
04A missing key returns nil — and puts nil prints an empty line.
05keys and values hand the pairs back as arrays.