Created
February 24, 2015 16:59
-
-
Save waruboy/1dfd23821832c755ca45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'time' | |
class Person | |
attr_accessor :name, :age, :sex, :birth_date, :birth_place, :death_date | |
## class methods | |
def Person.load_with_info(n, bdate, ddate=nil) | |
a = Person.new | |
a.name = n | |
a.birth_date = bdate | |
a.death_date = ddate | |
return a | |
end | |
## instance methods | |
def age | |
((alive? ? Time.now : Time.parse(death_date)) - Time.parse(birth_date)).to_i / 60 / 60 / 24 / 365 | |
end | |
def alive? | |
death_date.nil? | |
end | |
end | |
class Musician < Person | |
attr_accessor :discography | |
end | |
class Painter < Person | |
attr_accessor :published_works | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment