Skip to content

Instantly share code, notes, and snippets.

@jetaggart
Created July 18, 2013 20:39
Show Gist options
  • Select an option

  • Save jetaggart/6032879 to your computer and use it in GitHub Desktop.

Select an option

Save jetaggart/6032879 to your computer and use it in GitHub Desktop.
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