我的任务是检查用户的给定输入是否包含字母"c"
或"s"
。我用一个管理,但我根本不知道写这个的正确方法。如何检查数组是否包含X或Y
我知道问题是"s" || "c"
。
print 'What can we do for you?'
user_input = gets.chomp
user_input.downcase!
if user_input.empty?
puts 'Well you will have to write something...!'
elsif user_input.include? 's' || 'c'
puts "We got ourselves some 's's and some 'c's"
user_input.gsub!(/s/, 'th')
user_input.tr!('c', 's')
puts "The Daffy version, #{user_input}!"
else
print "Nope, no 's' or 'c' found"
end
完美的人:)非常感谢!它如此简单,但这让我粘在屏幕上大约一个小时。我昨天刚刚开始了红宝石。 –