Created
March 22, 2017 00:53
-
-
Save geocodinglife/8aaad72f77bdb7b801181dc83cd827aa 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
class Car | |
attr_accessor :speed, :acceleration, :braking, :velocity | |
def initialize(velocity = 0) | |
@velocity = velocity | |
end | |
def accelerate(acceleration) | |
acceleration == 0 ? @velocity + 1 : @velocity + acceleration | |
end | |
def brake | |
@velocity = @velocity - 1 | |
end | |
def brake braking | |
@velocity = @velocity - braking | |
end | |
end | |
car = Car.new(3) | |
# p car.velocity | |
p car.accelerate(66) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment