Created
March 7, 2016 22:28
-
-
Save FaisalAl-Tameemi/9fba26c48c7a47116fb9 to your computer and use it in GitHub Desktop.
This file contains 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
require_relative('./car') | |
bmw = BMW.new("M4") | |
begin | |
bmw.accelerate | |
bmw.accelerate | |
rescue => e | |
puts e | |
end |
This file contains 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 Car | |
class TooFastException < StandardError | |
end | |
def initialize(model, top_speed) | |
@model = model | |
@top_speed = top_speed | |
@current_speed = 0 | |
end | |
def accelerate(how_fast) | |
raise TooFastException, "Car is too fast" unless (@current_speed + how_fast) > @top_speed | |
@current_speed += how_fast | |
end | |
end | |
class BMW < Car | |
def initialize(model) | |
super(model, 255) | |
end | |
def accelerate | |
super(120) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment