You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arian Treffer edited this page Nov 9, 2017
·
1 revision
Ruby-on-Rails TDD Example
Implemented Contact#age
Contacts/app/models/contact.rb
class Contact < ActiveRecord::Base
def age
unless date_of_birth.is_a?(Date)
return nil
end
age = Date.today.year - date_of_birth.year
age -= 1 if Date.today < date_of_birth + age.years #for days before birthday
age = 0 if age < 0
return age
end
end