Easy lexical replacement with Ruby's gsub method
gsub(pattern, hash) → new_str
In Ruby's String#gsub method, if the second argument is a Hash, and the matched text is one of its keys, the corresponding hash value is the replacement string.
ALTS = { "cat" => "man", "hat" => "mirror" }
"The cat in the hat".gsub(/.at/, ALTS)
=> "The man in the mirror"