Locked lesson.
About this lesson
Adding and removing items from a hash.
Exercise files
Download this lesson’s related exercise files.
Hash Manipulation.docx59 KB Hash Manipulation - Solution.docx
59.3 KB
Quick reference
Hash Manipulation
You can add and remove items to your hash later on programmatically.
When to use
Use this any time you want to add or remove something from your hash.
Instructions
To add an item to your hash:
favorite_pizza = {
"John" => "Pepperoni",
"Tim" => "Mushroom",
"Mary" => "Cheese"
}
favorite_pizza["Steve"] = "Mushroom"
To remove an item from your hash:
favorite_pizza.delete("Steve")
Hints & tips
- It's easy to add or remove an item from your hash programmatically
Lesson notes are only available for subscribers.