What if you could lock your data so no one could break your program by mistake?
Why Frozen objects in Ruby? - Purpose & Use Cases
Imagine you have a list of important settings in your Ruby program. You want to make sure no one changes these settings by mistake while the program runs.
If you try to protect these settings by just telling people not to change them, mistakes happen. Someone might accidentally change a value, causing bugs that are hard to find.
Frozen objects let you lock your data so Ruby will stop any changes. This means your important settings stay safe and your program stays reliable.
settings = { theme: 'dark', language: 'en' }
# Someone can change settings[:theme] = 'light' by mistakesettings = { theme: 'dark', language: 'en' }.freeze
# Now settings cannot be changed, Ruby raises an error if triedIt enables you to create safe, unchangeable data that keeps your program stable and predictable.
Think of a frozen object like a locked recipe book. Once locked, no one can change the recipe, so every cake you bake tastes just right.
Frozen objects prevent accidental changes to data.
They help keep your program stable and bug-free.
Using freeze is like locking important information safely.