Skip to content

Instantly share code, notes, and snippets.

@geocodinglife
Created March 22, 2017 00: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 geocodinglife/8aaad72f77bdb7b801181dc83cd827aa to your computer and use it in GitHub Desktop.
Save geocodinglife/8aaad72f77bdb7b801181dc83cd827aa to your computer and use it in GitHub Desktop.
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