Created
October 10, 2018 20:53
-
-
Save sevperez/a1dd379442082af1707964c3a5954aa6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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