我怎样才能得到两个相同的单词(小写和大写)?

时间:2018-09-27 20:58:15

标签: ruby

这是一个示例:

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

如何在此代码中实现orand

1 个答案:

答案 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