0
0
Rubyprogramming~10 mins

Frozen objects 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.

Ruby
str = "hello"
str.[1]
Drag options to blanks, or click blank then click option'
Aseal
Bfreeze
Clock
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like lock or seal which don't exist in Ruby.
2fill in blank
medium

Complete the code to check if the array is frozen.

Ruby
arr = [1, 2, 3]
puts arr.[1]
Drag options to blanks, or click blank then click option'
Afrozen?
Bis_frozen
Clocked?
Dimmutable?
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like is_frozen or locked?.
3fill in blank
hard

Fix the error in the code that tries to modify a frozen string.

Ruby
str = "hello".[1]
str << " world"
Drag options to blanks, or click blank then click option'
Afreeze
Bclone
Cdup
Dcopy
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to modify the frozen string directly.
4fill in blank
hard

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

Ruby
hash = {a: 1, b: 2}.[1]
puts hash.[2]
Drag options to blanks, or click blank then click option'
Afreeze
Bfrozen?
Cis_frozen
Dlock
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_frozen or lock which are not Ruby methods.
5fill in blank
hard

Fill all three blanks to freeze an array, check if it's frozen, and attempt to modify it safely.

Ruby
arr = [1, 2, 3].[1]
puts arr.[2]
arr = arr.[3]
arr << 4
puts arr
Drag options to blanks, or click blank then click option'
Afreeze
Bfrozen?
Cdup
Dclone
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to modify the frozen array directly without duplication.