replace strring by another string ruby

original_string = "Hello, world!"
replacement_string = original_string.gsub("world", "Ruby")
puts replacement_string
  • Define the original string as "Hello, world!"
  • Define the replacement string by using the gsub method to replace "world" with "Ruby" in the original string
  • Print the replacement string to the console