Accessing and setting values
📖 Scenario: You are managing a small store's inventory using a Ruby program. You need to keep track of the quantity of different fruits available.
🎯 Goal: Build a Ruby program that creates a hash with fruit quantities, updates the quantity of one fruit, and then prints the updated quantity.
📋 What You'll Learn
Create a hash named
inventory with exact keys and valuesCreate a variable named
fruit_to_update with the exact string valueUpdate the quantity of the fruit in the
inventory hash using the variablePrint the updated quantity of the fruit using
puts💡 Why This Matters
🌍 Real World
Managing inventory quantities in a store or warehouse is a common task. Using hashes to store and update product counts helps keep track of stock easily.
💼 Career
Many programming jobs require working with data structures like hashes or dictionaries to manage and update information efficiently.
Progress0 / 4 steps