新手问题 菜鸟求助

chankaward · October 19, 2012 · Last by cxh116 replied at October 19, 2012 · 2173 hits
puts "What year you was born ?"
while true
year = gets.chomp
if year == # 请问这里应该怎样写呢?
  return true
else
  puts " ***only input number***"
end
end

正则行吗?

简单版:year =~ /^\d+$/

#1 楼 @cxh116 只能是数字 return true 应该怎样写呢

#3 楼 @chankaward

... 看你自己需求了,比如你可以直接年龄给打印出来 puts year

还好没积分,不然搞得我像是在刷积分一样

You need to Sign in before reply, if you don't have an account, please Sign up first.