menu
This method is used to replace the first occurrence of a specified pattern. 

Example:

text = "Hello, World! This is a test. Hello, Universe!" 
new_text =text.sub("Hello", "Hi") 
puts new_text # => "Hi, World! This is a test. Hello, Universe!"