Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created October 10, 2018 20:53
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 sevperez/a1dd379442082af1707964c3a5954aa6 to your computer and use it in GitHub Desktop.
Save sevperez/a1dd379442082af1707964c3a5954aa6 to your computer and use it in GitHub Desktop.
class Runner
attr_reader :name, :strategy
attr_writer :strategy
def initialize(name, strategy)
@name = name
@strategy = strategy
end
def run
case @strategy
when :jog
puts "#{@name} is now jogging at a comfortable pace."
when :sprint
puts "#{@name} is now sprinting full speeed!"
when :marathon
puts "#{@name} is now running at a steady pace."
else
puts "#{@name} is now running."
end
end
end
class Race
attr_reader :runners
def initialize(runners)
@runners = runners
end
def start
@runners.each { |runner| runner.run }
end
end
alice_ruby = Runner.new("Alice Ruby", :jog)
florence_joyner = Runner.new("Florence Joyner", :sprint)
eliud_kipchoge = Runner.new("Eliud Kipchoge", :marathon)
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