Skip to content

Instantly share code, notes, and snippets.

@FaisalAl-Tameemi
Created March 7, 2016 22:28
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 FaisalAl-Tameemi/9fba26c48c7a47116fb9 to your computer and use it in GitHub Desktop.
Save FaisalAl-Tameemi/9fba26c48c7a47116fb9 to your computer and use it in GitHub Desktop.
require_relative('./car')
bmw = BMW.new("M4")
begin
bmw.accelerate
bmw.accelerate
rescue => e
puts e
end
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