Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions models/automobile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Automobile
def initialize(color, make, model, year)
@color = color
@make = make
@model = model
@year = year
end

def number_of_wheels
number_of_wheels = 4
end

automobile = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be inside your Automobile class definition

automobile[:color] = "Red"
automobile[:make] = "SUV"
automobile[:model] = "Honda"
automobile[:year] = 2008

Car = Struct.new(:automobile, :method)
car = Car.new( {color: "Blue", make: "BMW", model: "sedan", year: 2013} )
end






# Panda Assignment
# ----------------

# 1. Create a class definition for an automobile
# 2. The class should have the following characteristics:
# * Should have a class method that returns the number of wheels it has
# * Should have instance variables for color, make, model, and year
# * I should be able to pass in a hash of color, make, model, and year to the class to update its variables
36 changes: 36 additions & 0 deletions models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Vehicle < Automobile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have Vehicle as the base class, which Automobile inheriting from it.

class Automobile < Vehicle


@@vehicles = []
vehicle = Vehicle.new
@@vehicles.push(vehicle)


def filter?
vehicle = Vehicle.new
if vehicle.color == "blue" && vehicle.make == "honda" && vehicle.model = "accord"
end

end

class Motorcycle < Vehicle
def number_of_tires
number_of_tires = 2
end
end









# Tiger Assignment
# ----------------

# 1. Create a Vehicle class that automobile inherits from
# 2. Create a Motorcycle class that inherits from vehicle
# 3. Show the motorcycle class overriding the vehicle's class method for number of tires


27 changes: 27 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Vehicle
end

describe Vehicle do
it "should track all the vehicles made" do
@@vehicles = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point, you're testing ruby array code. You shouldn't have @@ in your tests. at it's simplest:

count = Vehicle.vehicle_count
Vehicle.new
Vehicle.vehicle_count.should eq(count+1)

or, a little easier to read:

expect {
  Vehicle.new
}.to change(Vehicle, :vehicle_count).by(1)

vehicle = Vehicle.new
@@vehicles.push(vehicle)
@@vehicles.length.should eq(1)
end

it "should filter blue honda accords" do
vehicle = Vehicle.new
vehicle.filter?
end
end





# Eagle Assignment
# ----------------

# 1. Create a class variable (@@) in the Vehicle that tracks all vehicles mde
# 2. Create a class method that let's you filter the vehicles to only blue honda accords (using our enuerable filters)
# 3. Do it all using TDD (of course!)