Skip to content

Instantly share code, notes, and snippets.

@ryanholm
Last active August 29, 2015 14:02
Show Gist options
  • Save ryanholm/e980959c4a017a6c8f95 to your computer and use it in GitHub Desktop.
Save ryanholm/e980959c4a017a6c8f95 to your computer and use it in GitHub Desktop.
BLOC Intro to Classes 2
#CP 1
class Car
attr_accessor :make, :model, :year
def initialize(make, model, year)
@make, @model, @year = make, model, year
end
end
#RSpec
describe "Car" do
describe "initialize" do
it "should take make, model and year" do
new_car = Car.new("Acura", "Integra", 1998)
new_car.make.should eq("Acura")
new_car.model.should eq("Integra")
new_car.year.should eq(1998)
end
end
end
CP#2
class Car
attr_accessor :make, :model, :year
def initialize(make, model, year)
@make, @model, @year = make, model, year
end
def self.wheels
4
end
def self.axles
2
end
end
#RSpec
describe "Car" do
describe "initialize" do
it "should take make, model and year" do
new_car = Car.new("Acura", "Integra", 1998)
new_car.make.should eq("Acura")
new_car.model.should eq("Integra")
new_car.year.should eq(1998)
end
end
describe "wheels" do
it "should return a standard number of wheels for any car" do
Car.wheels.should eq(4)
end
end
describe "axles" do
it "should return a standard number of axles for any car" do
Car.axles.should eq(2)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment