From: Patrick Hurley Date: 2006-07-11T02:50:37+09:00 Subject: Re: Real newbie question about methods On 7/10/06, simonh wrote: > What I want to do is put this in a method:- > ------------------------------------------------ > def check_age(age) > print "Please enter your age: " > age = gets.chomp.to_i > eligible = 18..30 > if age < 18 > print "Sorry, too young." > elsif eligible === age > print "Have a great holiday!" > else > print "Input not understood." > check_age(age) # trying recursion here > end > check_age() > end > ------------------------------------------------ > > But it doesn't work. How do I get the value entered by the user into > the method parameter? > > Many thanks > Probably something like: def check_age(age) eligible = 18..30 if age < 18 print "Sorry, too young." elsif eligible === age print "Have a great holiday!" true # provide a positive result else print "Input not understood." end end print "Please enter your age: " check_age(gets.chomp.to_i) # of course I would use a case # make eligble a constant # and if required provide the flow control (probably not recursive) in another function Good luck pth