Complete the code to use the bang method that reverses the string in place.
str = "hello" str.[1]
reverse which returns a new string but does not modify the original.upcase or capitalize.The reverse! method reverses the string in place, modifying the original string.
Complete the code to remove trailing whitespace from the string using a bang method.
text = "hello " text.[1]
strip which returns a new string but does not change the original.chomp which removes newline characters, not whitespace.The strip! method removes leading and trailing whitespace in place, modifying the original string.
Fix the error by choosing the correct bang method to convert the string to uppercase in place.
name = "alice" name = name.[1]
upcase which returns a new string but does not modify the original.capitalize! which only capitalizes the first letter.The upcase! method converts the string to uppercase in place. It returns nil if no changes are made, so assigning back is usually unnecessary.
Fill both blanks to remove all exclamation marks from the string in place and then reverse it in place.
msg = "Wow!!!" msg.[1]("!") msg.[2]
delete without the bang, which returns a new string.delete! removes specified characters from the string in place. Then reverse! reverses the string in place.
Fill all three blanks to replace 'cat' with 'dog' in place, then upcase the string in place, and finally remove trailing spaces in place.
sentence = "the cat is cute " sentence.[1]("cat", "dog") sentence.[2] sentence.[3]
gsub and gsub!.gsub! replaces text in place. Then upcase! changes all letters to uppercase in place. Finally, rstrip! removes trailing spaces in place.