这是一个示例:
Puts "#{input}"
If input == "Hello" || "hello". <== What to be able to enter same word but lower case and uppercase
Puts "nice to meet you"
Elsif input == "Bonjour" || "bonjour"
Puts "that's french"
Else
Puts "user input "
End
如何在此代码中实现or
,and
?
答案 0 :(得分:0)
使用downcase将输入更改为小写,然后与小写单词进行比较。
def respond(input)
case input.downcase
when "hello" then puts "hello"
when "bonjour" then puts "that\'s french"
else puts "user input"
end
end