From: simonh Date: 2006-07-11T05:10:05+09:00 Subject: Re: Real newbie question about methods studlee2@gmail.com wrote: > Agreed that the regexp wouldn't work for your code. I would have > written it like this (like I said before your code is cleaner) > > def check_age > print "Please enter your age: " > age = gets.chomp > target = 18..30 > valid = /\d{2}/ > > if valid.match(age) > if target === age.to_i > puts 'Have A Nice Holiday' > elsif age.to_i < 18 > puts 'Too Young' > elsif age.to_i > 30 > puts 'Too Old' > end > else > puts "Usage: <18..30>" > check_age # Try again > end > end > > check_age > > _Steve > thanks Steve, I like that. a nested if that checks against a rexexp first. mind if I add it to my Library Of Useful Code Samples For When I Get Stuck?