Hi --

On Wed, 19 Jul 2006, S Wayne wrote:

> A couple of things:
>
> First, as Daniel already said, why not put the information right in the
> loop? However, don't go recursive there, I'd do a loop instead:
>
> age = 0
> target_age = 30..65 # ;)
> while ! target === age

s/target/target_age/   Also, "until" is a nicer way to do while ! .

>  print "Please enter your age: (as two digits): "
>  result = gets
>  age = result.chomp.to_i

No need to chomp:

   age = gets.to_i

>  case age
>  when age < 30

Hang on....  Remember that a case statement works like this:

   case a
   when b

is equivalent to:

   if b === a

So what you've got is:

   if (age < 30) === age

which is going to be either:

   if true === age

or

   if false === age

Neither of those is ever true when age is an integer, so the test will
never succeed.

A simple if construct will work fine:

   if age < 30
     ...
   elsif age > 75
     ...
   else
     ...
   end

>    puts 'Sorry, too young.'
>  when age > 75
>     puts 'Sorry, too old.'
>  else
>     puts 'Hava a nice holiday!'
>     return age
>  end
>  puts "Remember, age must be entered as two digits, e.g. 35"
> end
>
> check_age

No such method :-)


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
http://www.manning.com/black     => RUBY FOR RAILS (reviewed on
                                     Slashdot, 7/12/2006!)
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
dblack / wobblini.net              => me