Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
38 changes: 19 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.3)
activesupport (= 3.2.3)
activemodel (3.2.9)
activesupport (= 3.2.9)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activerecord (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.3)
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
builder (3.0.4)
diff-lcs (1.1.3)
i18n (0.6.0)
multi_json (1.3.4)
pg (0.13.2)
rake (0.9.2.2)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.0)
rspec-expectations (2.10.0)
i18n (0.6.1)
multi_json (1.5.0)
pg (0.14.1)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
tzinfo (0.3.33)
rspec-mocks (2.12.0)
tzinfo (0.3.35)

PLATFORMS
ruby
Expand Down
4 changes: 2 additions & 2 deletions block_review.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'
require 'bundler/setup'

require_relative 'db/setup'
Dir.glob("./**/*.rb").each {|f| require f}
#require_relative 'db/setup'
Dir.glob("./models/*.rb").each {|f| require f}

puts "Serenity now!"
17 changes: 17 additions & 0 deletions models/automobile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'vehicle'
class Automobile < Vehicle

attr_reader :color, :make, :model, :year

def initialize(options = {})
@color = options[:color]
@make = options[:make]
@model = options[:model]
@year = options[:year]
add_to_vehicles
end

def add_to_vehicles
@@vehicles << self
end
end
14 changes: 14 additions & 0 deletions models/motorcycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative 'vehicle'
class Motorcycle < Vehicle
def initialize
add_to_vehicles
end

def self.wheels
2
end

def add_to_vehicles
@@vehicles << self
end
end
18 changes: 18 additions & 0 deletions models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Vehicle

@@vehicles = []

def self.wheels
4 # Hardcoded value since there were no further intructions regarding what an automobile is.
end

def self.blue_honda_accords
automobiles = @@vehicles.select { |vehicle| vehicle.class == Automobile }
automobiles.keep_if do |automobile|
automobile.color == 'blue' &&
automobile.make == 'Honda' &&
automobile.model == 'Accord'
end
end
Copy link
Member

Choose a reason for hiding this comment

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

We talked about this code in office hours... just an alternative way:

class Automobile
  def ==(other)
    color == other.color && make == other.make && model == other.model
  end
end

####
blue_honda_accord = Automobille.new( make: "Honda", model: "Accord", color: "blue" )
@@vehicles.select { |vehicle| vehicle.class == Automobile }.select {|a| a == blue_honda_accord }


end
27 changes: 27 additions & 0 deletions spec/models/automobile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe Automobile, '.wheels' do
it 'returns the number of wheels' do
Automobile.wheels.should eq 4
end
end

describe Automobile, '.initialize' do
it 'can receive a hash containing color, make, model and year to update its variables' do
car = Automobile.new(color: 'blue', make: 'BMW', model: '325i', year: 1995)

expect(car.color).to eq 'blue'
expect(car.make).to eq 'BMW'
expect(car.model).to eq '325i'
expect(car.year).to eq 1995
end
end

describe Automobile, '#add_to_vehicles' do
it 'adds itself to @@vehicles array' do
@@vehicles = []
car = Automobile.new(color: 'blue', make: 'BMW', model: '325i', year: 1995)

expect(@@vehicles.count).to eq 1
end
end
16 changes: 16 additions & 0 deletions spec/models/motorcycle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Motorcycle, '.wheels' do
it 'overrides Vehicle and returns 2 wheels' do
expect(Motorcycle.wheels).to eq 2
end
end

describe Motorcycle, '#add_to_vehicles' do
it 'adds itself to @@vehicles array' do
@@vehicles = []
motorcycle = Motorcycle.new

expect(@@vehicles.count).to eq 1
end
end
22 changes: 22 additions & 0 deletions spec/models/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

describe Vehicle, '@@vehicles' do
it 'stores all vehicles in a global variable' do
@@vehicles = []
Automobile.new(color: 'blue', make: 'BMW', model: '325i', year: 1995)
Motorcycle.new
expect(@@vehicles.count).to eq 2
end
end

describe Vehicle, '#blue_honda_accords' do
it 'returns only blue honda accords' do
car = Automobile.new(color: 'blue', make: 'Honda', model: 'Accord', year: 1995)
another_car = Automobile.new(color: 'blue', make: 'BMW', model: '325i', year: 1995)
motorcycle = Motorcycle.new

blue_hondas = Vehicle.blue_honda_accords

expect(blue_hondas).to eq [car]
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rspec'
require 'bundler/setup'
require_relative '../models/automobile'
require_relative '../models/vehicle'
require_relative '../models/motorcycle'