Created
July 18, 2013 20:39
-
-
Save jetaggart/6032879 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
| module Drivable | |
| extend ActiveSupport::Concern | |
| class TemplateError < RuntimeError; end | |
| included | |
| validates :direction, :presence => true | |
| validates :speed, :presence => true | |
| end | |
| def turn(new_direction) | |
| self.direction = new_direction | |
| end | |
| def brake | |
| self.speed = 0 | |
| end | |
| def accelerate | |
| self.speed = [speed + acceleration, top_speed].min | |
| end | |
| def top_speed | |
| raise TemplateError, "The Drivable module requires the " + | |
| "including class to define a " + | |
| "top_speed method" | |
| end | |
| def acceleration | |
| raise TemplateError, "The Drivable module requires the " + | |
| "including class to define an " + | |
| "acceleration method" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment