Explore Ruby Hash Methods: keys, values, each
📖 Scenario: You work at a small bookstore. You have a list of books with their prices stored in a Ruby hash. You want to learn how to get all the book titles, all the prices, and how to look at each book and its price one by one.
🎯 Goal: Build a Ruby program that creates a hash of books and prices, stores the list of book titles and prices separately, and then prints each book with its price using a loop.
📋 What You'll Learn
Create a hash called
books with these exact entries: 'Ruby Basics' => 25, 'JavaScript Guide' => 30, 'Python 101' => 20Create a variable called
titles that stores all the keys from the books hashCreate a variable called
prices that stores all the values from the books hashUse
books.each with block variables title and price to print each book title and its price💡 Why This Matters
🌍 Real World
Managing collections of items with prices is common in stores, inventories, and online shops. Hashes help store and access this data easily.
💼 Career
Understanding how to work with hashes and their methods is essential for Ruby developers working on backend systems, data processing, and web applications.
Progress0 / 4 steps