Skip to content

Instantly share code, notes, and snippets.

@FaisalAl-Tameemi
Created March 9, 2016 19:36
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/bbbcd89370e8844bf7fa to your computer and use it in GitHub Desktop.
Save FaisalAl-Tameemi/bbbcd89370e8844bf7fa to your computer and use it in GitHub Desktop.
Classes review + Module example
require_relative('./car_methods')
class Car
attr_accessor :current_speed
def initialize(model, color)
@model = model
@color = color
@current_speed = 0
end
include CARMETHODS
end
module CARMETHODS
def drive_forward
self.current_speed += 50
end
def drive_reverse
self.current_speed -= 20
end
end
require_relative('./car')
require_relative('./truck')
prius = Car.new("Toyota Prius", "Light Brown")
prius.drive_forward
puts "The Prius is going at a speed of #{prius.current_speed}"
f150 = Truck.new("Ford F150", "Dark Blue")
f150.drive_forward
f150.drive_forward
puts "The F150 is going at a speed of #{f150.current_speed}"
require_relative('./car_methods')
class Truck
attr_accessor :current_speed
def initialize(model, color)
@model = model
@color = color
@current_speed = 0
end
include CARMETHODS
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment