In ruby how do you tell if a string input is in uppercase or lowercase?

后端 未结 3 1457
后悔当初
后悔当初 2021-01-13 06:18

I am trying to write a program that when a single letter is inputted, if it\'s in uppercase, leave it in uppercase and return it, and if it\'s in lowercase, then convert to

3条回答
  •  离开以前
    2021-01-13 06:59

    For a single string you can use start_with? method as well.

    user_input = gets.chomp
    
    if user_input.start_with?(user_input.downcase)
        user_input.upcase!
    end
    

提交回复
热议问题