-
-
Save 0x0dea/11c33823029559ba270f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sentence = "For now you ask why." | |
hash = { | |
FOR: "4", | |
YOU: "U", | |
WHY: "Y", | |
} | |
# Start with an upcased copy of the original. | |
slang = sentence.upcase | |
hash.each do |word, alt| | |
# Use gsub! (note the bang) to modify the string in-place. | |
slang.gsub!(/\b#{word}\b/, alt) | |
end | |
puts slang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sentence = "For now you ask why." | |
hash = { | |
"FOR" => "4", | |
"YOU" => "U", | |
"WHY" => "Y", | |
} | |
hash.default_proc = -> k, v { v } | |
puts sentence.upcase.gsub /\w+/, hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment