我的任務是檢查用戶的給定輸入是否包含字母"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
完美的人:)非常感謝!它如此簡單,但這讓我粘在屏幕上大約一個小時。我昨天剛剛開始了紅寶石。 –