Complete the code to replace all occurrences of 'cat' with 'dog' in the string.
text = "cat and cat" new_text = text.[1]("cat", "dog") puts new_text
The gsub method replaces all occurrences of the pattern in the string.
Complete the code to replace only the first occurrence of 'apple' with 'orange'.
fruits = "apple, apple, apple" new_fruits = fruits.[1]("apple", "orange") puts new_fruits
The sub method replaces only the first occurrence of the pattern.
Fix the error in the code to replace all digits with '#' characters.
text = "Phone: 123-456-7890" new_text = text.[1](/\d/, "#") puts new_text
To replace all digits, use gsub with the digit pattern.
Fill both blanks to create a hash mapping words to their lengths, but only for words longer than 4 letters.
words = ["apple", "cat", "banana", "dog"] lengths = {word: word.[1] for word in words if word.[2] 4} puts lengths
Use length to get word length and > to filter words longer than 4.
Fill all three blanks to create a hash with uppercase words as keys and their lengths as values, only for words with length greater than 3.
words = ["tree", "sun", "flower", "sky"] result = {word.[1]: word.[2] for word in words if word.[3] 3} puts result
Use upcase to uppercase keys, length for values, and > to filter words longer than 3.