-
-
Save supertopher/5760709 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 Vehicle | |
@wheels = 4 | |
def initialize args | |
@color = args[:color] | |
end | |
def drive | |
@status = :driving | |
end | |
def brake | |
@status = :stopped | |
end | |
def needs_gas? | |
rand(3) == 0 | |
end | |
def to_s | |
"You are looking goood in your vehicle. It has freshly waxed #{@color} paint" | |
end | |
end | |
class Car < Vehicle | |
end | |
class Bus < Vehicle | |
attr_reader :passengers, :wheels, :fare | |
def initialize(passengers, args) | |
@color = args[:color] | |
@wheels = args[:wheels] | |
@num_seats = args[:num_seats] | |
@fare = args[:fare] | |
@passengers = passengers | |
@floors = args[:floors] | |
end | |
def drive | |
return self.brake if stop_requested? | |
@status = :driving | |
end | |
def admit_passenger(passenger,money) | |
if money > @fare | |
@passengers << passenger | |
return "Passenger Admitted" | |
else | |
return "Passage DENIED!" | |
end | |
end | |
def stop_requested? | |
rand(2) == 0 | |
end | |
end | |
class Motorbike < Vehicle | |
@wheels = 2 | |
def drive | |
@status = :driving | |
@speed = :fast | |
end | |
def weave_through_traffic | |
@laura_health = 10 | |
@status = :driving_like_a_crazy_person | |
end | |
def laura_drinks_while_riding | |
@laura_health ||= 10 | |
@laura_health = (@laura_health - 1) | |
if @laura_health < 7 | |
return "Laura has been drinking. But swears she didn't fall off the bike" | |
else | |
return "I'm FINE!" | |
end | |
end | |
end | |
ferrari = Car.new({color: "Corsa Rosa"}) | |
puts ferrari | |
puts "Does the ferrari need gas?" | |
puts ferrari.needs_gas? | |
puts "Rollin' like 2Pac?" | |
puts ferrari.drive | |
puts | |
pimpmobile = Bus.new(["Chris", "Laura", "Jenny", "Brick", "Navid", "Anne", "Mufasa!"], | |
{color: "Totally Sick Mural", wheels: 29, num_seats: 8, fare: 13, floors: 2}) | |
puts pimpmobile | |
puts "Does the pimpmobile need gas?" | |
puts pimpmobile.needs_gas? | |
puts "Rolling like 2Pac?" | |
puts pimpmobile.drive | |
puts "Can 'The Man' Get on the bus?" | |
puts pimpmobile.admit_passenger("The Man", 0) | |
puts "Who is on the bus?" | |
puts pimpmobile.passengers.to_s | |
puts | |
vespa = Motorbike.new({color: "Black. Hardcore Flat Black."}) | |
puts vespa | |
puts "Does the vespa need gas?" | |
puts vespa.needs_gas? | |
puts "Rolling like 2Pac?" | |
puts vespa.drive | |
puts "STEP ON IT" | |
puts vespa.weave_through_traffic | |
puts "Laura went to the bar on her vespa" | |
puts vespa.laura_drinks_while_riding | |
puts "Laura went to alot of bars." | |
5.times {vespa.laura_drinks_while_riding} | |
puts vespa.laura_drinks_while_riding | |
puts | |
puts "Please don't drink and drive. Drinking is for Sailing." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment