F. Senault
6/2/2009 11:02:00 AM
Le 2 juin 2009 à 11:12, Max Williams a écrit :
> category = case age
> when < 12 : "child"
> when 13..17 : "minor"
> when 18..24 : "young ad*lt"
> when 25..49 : "ad*lt"
> when 50..64 : "middle aged"
> when > 65 : "senior"
> else : "not an age"
> end
As the others pointed out, there's no easy way to do what you want to.
On the other hand, if you know the bounds of your inputs, your method
isn't bad ; I'd write :
category = case age
when 0...12 then "child"
when 12...18 then "minor"
when 18...25 then "young ad*lt"
when 25...50 then "ad*lt"
when 50...65 then "middle aged"
when 65...999 then "senior"
else "not an age"
end
Note that the use of : within if's and case's has been deprecated in
Ruby 1.9 and the next versions.
Fred
--
Home, home again I like to be here when I can
When I come home cold and tired
It's good to warm my bones besides the fire
(Pink Floyd, Breathe Reprise)