I have a quick question on Ruby syntax: I am trying to write a program where it takes a string and replaces substrings with a different substring IF it contains the initial substring. Here is my code:
print "Thtring, pleathe!"
user_input = gets.chomp
if user_input.include? "s" || "S" || "cy" || "ce" || "ci"
user_input.gsub!(/s/, "th")
user_input.gsub!(/S/, "Th")
user_input.gsub!(/cy/, "th")
user_input.gsub!(/ce/, "th")
user_input.gsub!(/ci/, "th")
else
puts "No 's' found!"
end
puts "#{user_input}!"
This works fine until I have a sentence that doesn't contain "s" in it. Then it just prints the original string with no changes. Is there a logical operator that means AND/OR in Ruby? To replace all the ORs (||
) with. And if there isn't, how would I rewrite this to make it work?