Skip to content

Instantly share code, notes, and snippets.

@bendavis78
Last active April 11, 2016 17:06
Show Gist options
  • Save bendavis78/d5b5f03d941100f62e445ff7e168d252 to your computer and use it in GitHub Desktop.
Save bendavis78/d5b5f03d941100f62e445ff7e168d252 to your computer and use it in GitHub Desktop.
class Person
attr_accessor :first_name, :last_name, :gender, :age
def initialize(first_name, last_name, gender, age)
@first_name = first_name
@last_name = last_name
@gender = gender
@age = age
end
def introduction
puts "#{@first_name} #{@last_name} is a #{@age} year old #{@gender}"
end
end
class Student < Person
def action
puts "#{@first_name} is learning"
end
end
class Teacher < Person
def action
puts "#{@first_name} is teaching"
end
end
p = Teacher.new "Ben", "Davis", "male", 37
s = Student.new "John", "Doe", "male", 15
people = [p, s]
people.each do |person|
person.introduction
person.action
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment