codereview, .
, .
-, , .
def readable_age(years, months)
if years == 0
return months > 1 ? months.to_s + " months old" : months.to_s + " month old"
elsif years == 1
return months > 1 ? years.to_s + " year and " + months.to_s + " months old" : years.to_s + " year and " + months.to_s + " month old"
else
return months > 1 ? years.to_s + " years and " + months.to_s + " months old" : years.to_s + " years and " + months.to_s + " month old"
end
end
, , actionview, pluralize. -
def readable_age(years, months)
year_text = ''
if years == 0
year_text = "#{years} #{pluralize('year', years)} and "
end
"#{year_text}#{pluralize('month', months)} old"
end
.
def age(t)
dob = self.date_of_birth
months = (t.year * 12 + t.month) - (dob.year * 12 + dob.month)
readable_age(months / 12, 15 % 12)
end
, age, . , .