Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Runner
attr_reader :name
def initialize(name)
@name = name
end
def run
puts "#{@name} is now running."
end
end
class Jogger < Runner
def run
puts "#{@name} is now jogging at a comfortable pace."
end
end
class Sprinter < Runner
def run
puts "#{@name} is now sprinting full speeed!"
end
end
class Marathoner < Runner
def run
puts "#{@name} is now running at a steady pace."
end
end
class Race
attr_reader :runners
def initialize(runners)
@runners = runners
end
def start
@runners.each { |runner| runner.run }
end
end
alice_ruby = Jogger.new("Alice Ruby")
florence_joyner = Sprinter.new("Florence Joyner")
eliud_kipchoge = Marathoner.new("Eliud Kipchoge")
race = Race.new([alice_ruby, florence_joyner, eliud_kipchoge])
race.start
# Alice Ruby is now jogging at a comfortable pace.
# Florence Joyner is now sprinting full speeed!
# Eliud Kipchoge is now running at a steady pace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.