# Replace first value a return new string
sentence = 'pop poper'
sentence.sub('pop', 'stop')
=> 'stop poper'
puts sentence
=> 'pop poper'
# Replace all matches and return new string
sentence = 'pop poper'
sentence.gsub('pop', 'stop')
=> 'stop stoper'
puts sentence
=> 'pop poper'
# Replace first value and update existing string
sentence = 'pop poper'
sentence.sub!('pop', 'stop')
=> 'stop poper'
puts sentence
=> 'stop poper'
# Replace all matches and update string
sentence = 'pop poper'
sentence.gsub!('pop', 'stop')
=> 'stop stoper'
puts sentence
=> 'stop stoper'