[Rails] Re: calculate users age
Jonas Elfström
jonelf at gmail.com
Wed Jan 25 08:32:02 GMT 2006
On 1/24/06, Paul Barry <mail at paulbarry.com> wrote:
> This shows the errors in age_at better:
Thanks for pointing this out! I can't imagine why I did not think of this.
I am not in any way an endorser of trying to make code as short as
possible but out of curiosity I fixed my one-line class so that it now
correct but "unreadable":
def age_at(date, dob)
date.year - dob.year - (date.month-dob.month < 0 ? 1 :
date.day-dob.day < 0 ? 1:0)
end
--
Jonas Elfström
More information about the Rails
mailing list