代替执行:
puts "what type of input?"
input = gets.chomp
if %W[Int INT i I Ints ints].include?(input)
puts "enter int"
i = gets.to_i
我想使用正则表达式解释字符串用户输入。例如,>
puts "are you entering in a string, an int or a float?" case gets when /\A(string|s)\z/i puts "enter in a string" gets.chomp when /\A(int|i)\z/i puts "enter an int" gets.to_i when /\A(float|f)\z/i puts "enter a float" gets.to_f end
为了获得相同的结果但使用
if
语句而不是case
语句的语法是什么?
而不是:输入“什么类型的输入?”如果%W [Int INT i I Ints ints] .include?(input)放入“ enter int”,则输入= gets.chomp i = gets.to_i我想使用正则表达式解释字符串用户输入。对于...
gets
返回字符串with