Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to freeze the string.
Ruby
str = "hello" str.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like
lock or seal which don't exist in Ruby.✗ Incorrect
The freeze method makes the object immutable in Ruby.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like
is_frozen or locked?.✗ Incorrect
The frozen? method returns true if the object is frozen.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to modify the frozen string directly.
✗ Incorrect
Duplicating the string with dup creates a mutable copy to modify.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
is_frozen or lock which are not Ruby methods.✗ Incorrect
Use freeze to freeze the hash and frozen? to check it.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to modify the frozen array directly without duplication.
✗ Incorrect
Freeze the array, check if frozen, then duplicate it to modify safely.