I don't know regex. I want to learn regex, but learning regex just for the sake of regex would be quite boring.
So I decided to learn Ruby as well (which so far looks a lot like Python, which I'm familiar with).
My first program attempts to speak with a combination of both Daffy Duck's lisp and Elmer Fudd's verbal apraxia.
It works quite well, but it looks quite messy already. How does one properly combine Ruby and (repeated) regex substitutions?
def lisp(input)
return input.downcase.gsub(/s/, "th").gsub(/er/, "uh").gsub(/r|l/, "w").capitalize
end
print lisp("What's your input?")
user_input = gets.chomp
puts lisp(user_input)
I downcase everything to make the regex easier and capitalize at the end to turn it back into a proper sentence.
Usage:
What'th youw input? It's rabbit season!
It'th wabbit theathon!
What'th youw input? My super soaker carries 2 liters of water!
My thupuh thoakuh cawwieth 2 wituhth of watuh!
puts
does the same asprint
, and it adds a new line. And this is defiantly hilarious. \$\endgroup\$