0
0
Rubyprogramming~10 mins

Immutable data with freeze in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to freeze the string so it cannot be changed.

Ruby
name = "Ruby".[1]
name << "Lang"
Drag options to blanks, or click blank then click option'
Aupcase
Bfreeze
Creverse
Dcapitalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using string methods that modify content instead of freezing.
Not calling any method and expecting immutability.
2fill in blank
medium

Complete the code to freeze the array so it cannot be modified.

Ruby
numbers = [1, 2, 3].[1]
numbers << 4
Drag options to blanks, or click blank then click option'
Areverse
Bsort
Cfreeze
Duniq
Attempts:
3 left
💡 Hint
Common Mistakes
Using sorting or reversing methods instead of freezing.
Trying to modify without freezing first.
3fill in blank
hard

Fix the error by freezing the hash so it cannot be changed.

Ruby
config = {mode: 'dark', volume: 10}
config.[1]
config[:mode] = 'light'
Drag options to blanks, or click blank then click option'
Afreeze
Bdelete
Cdup
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that remove or copy instead of freezing.
Not freezing before trying to modify.
4fill in blank
hard

Fill both blanks to create a frozen array and check if it is frozen.

Ruby
arr = [10, 20, 30].[1]
puts arr.[2]
Drag options to blanks, or click blank then click option'
Afreeze
Bfrozen?
Cempty?
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty? or length instead of frozen?.
Not freezing the array before checking.
5fill in blank
hard

Fill all three blanks to freeze a nested hash and check if the nested array is frozen.

Ruby
settings = {theme: 'blue', options: [1, 2, 3]}
settings = settings.[1]
puts settings[:options].[2]
settings[:options].[3]
Drag options to blanks, or click blank then click option'
Afreeze
Bfrozen?
Ddup
Attempts:
3 left
💡 Hint
Common Mistakes
Assuming freezing outer hash freezes nested objects.
Not freezing nested array separately.