Merge and Update Methods
📖 Scenario: You are managing a small online store's inventory. You have a list of products with their current stock counts. Occasionally, you receive new shipments that update the stock counts or add new products.
🎯 Goal: Build a Ruby program that merges two hashes representing product stocks. The program will update existing products' stock counts and add new products from the shipment.
📋 What You'll Learn
Create a hash called
current_stock with exact product names and stock countsCreate a hash called
new_shipment with exact product names and stock countsUse the
merge! method with a block to update current_stock by adding stock counts from new_shipmentPrint the updated
current_stock hash💡 Why This Matters
🌍 Real World
Managing inventory updates in small business software or online stores often requires merging stock data from different sources.
💼 Career
Understanding how to merge and update hashes is useful for backend developers working with data aggregation, inventory systems, or configuration management.
Progress0 / 4 steps