没有输入时,红宝石显示#{}(ruby show #{} when nothing is entered)
print"Do you want to calculate your invoice? Please enter Yes(Y) or No(N)... "
calculate_cont = ""
while calculate_cont = gets.chomp()
calculate_cont.to_s
calculate_cont.upcase!
case calculate_cont
when "Y", "YES"
<calculations>
print "Do you wish to continue? "
when "N", "NO"
puts "Thank you! Press Enter to exit!"
gets()
exit()
else
puts "Error: #{calculate_cont} is not a valid entry!
puts "Please Enter a valid response! Yes(Y) or No(N)"
print "Do you wish to continue? "
end
end
当用户输入除YES或NO以外的任何其他内容时,它将使用#{calculate_cont}显示他输入的文本。 如果用户只是使用#{calculate_cont}按Enter键,我如何告诉用户他输入“Nothing”? 能做到吗?
谢谢
print"Do you want to calculate your invoice? Please enter Yes(Y) or No(N)... " calculate_cont = "" while calculate_cont = gets.chomp() calculate_cont.to_s calculate_cont.upcase! case calculate_cont when "Y", "YES" <calculations> print "Do you wish to continue? " when "N", "NO" puts "Thank you! Press Enter to exit!" gets() exit() else puts "Error: #{calculate_cont} is not a valid entry! puts "Please Enter a valid response! Yes(Y) or No(N)" print "Do you wish to continue? " end endwhen the user enter anything else other than YES or NO it will show the text that he input using #{calculate_cont}. How can i tell the user that he enters "Nothing" if the user just hit enter using #{calculate_cont}? can it be done?
Thanks
最满意答案
是的,如果您正在调用gets.chomp且用户未输入任何值,则输出将为空字符串。 只是换个条件
DO SOMETHING if calculate_cont.empty?Yes, if you are calling gets.chomp and the user entered no value, the output will be an empty string. Just put another conditional
DO SOMETHING if calculate_cont.empty?更多推荐
发布评论