Nil as the absence of value
📖 Scenario: Imagine you are managing a list of people and their favorite colors. Sometimes, a person might not have a favorite color yet. In Ruby, nil is used to show that something has no value.
🎯 Goal: You will create a Ruby program that uses nil to represent missing favorite colors and then check for those missing values.
📋 What You'll Learn
Create a hash called
people_colors with exact keys and valuesUse
nil to represent no favorite colorCreate a variable called
missing_color_count to count how many people have no favorite colorUse a
for loop with variables person and color to iterate over people_colorsPrint the number of people with no favorite color using
puts💡 Why This Matters
🌍 Real World
In real programs, <code>nil</code> helps show when information is missing or unknown, like a missing phone number or address.
💼 Career
Understanding <code>nil</code> is important for Ruby developers to handle data correctly and avoid errors when values are missing.
Progress0 / 4 steps