Skip to content

Instantly share code, notes, and snippets.

@waruboy
Created February 24, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waruboy/1dfd23821832c755ca45 to your computer and use it in GitHub Desktop.
Save waruboy/1dfd23821832c755ca45 to your computer and use it in GitHub Desktop.
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