Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished but with a fair bit of questions #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
31 changes: 31 additions & 0 deletions block_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,34 @@
Dir.glob("./**/*.rb").each {|f| require f}

puts "Serenity now!"

class Automobile < ActiveRecord::Base
def initialize
@color = color
Copy link
Member

Choose a reason for hiding this comment

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

The only reason this may appear to work is that ActiveRecord takes control of the initialize method.

So, when you use ActiveRecord, you can't use initialize -- you have to use other weird methods.

tl;dr -- ActiveRecord will handle the assignments when you do automobile = {color: "Black", make: "SUV", model: "Range Rover", year: 2013}

@make = make
@model = model
@year = year
end

def number_of_tires
4
end
end

automobile = {color: "Black", make: "SUV", model: "Range Rover", year: 2013}
puts automobile

class Vehicle < Automobile
@@count = Vehicle.count

def blue_honda_accords
#not sure here
Copy link
Member

Choose a reason for hiding this comment

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

OK, so you're not sure. If I needed Hondas (in active record), I would

Automobile.where(make: "honda")

And if I needed blue cars:

Automobile.where(color: "blue")

And you can combine them:

Automobile.where(make: "honda").where(color: "blue")

end
end

class Motorcycle < Automobile
def number_of_tires
2
end
end

24 changes: 24 additions & 0 deletions models/panda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Automobile < ActiveRecord::Base
def initialize
@color = color
@make = make
@model = model
@year = year
end

def number_of_tires
4
end
end

automobile = {color: "Black", make: "SUV", model: "Range Rover", year: 2013}

class Vehicle < Automobile
end

class Motorcycle < Automobile
def number_of_tires
2
end
end

32 changes: 32 additions & 0 deletions spec/block_review_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Automobile
end

class Vehicle
end

class Motorcycle
end

describe Automobile do
it "should have a attributes" do
@color = color
@make = make
@model = model
@year = year
end
it "should have 4 tires" do
number_of_tires = 4
Copy link
Member

Choose a reason for hiding this comment

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

This is not an assertion, it's an assignment. If you wanted to run a test:

Automobile.number_of_times.should eq(4)

end
end

describe Vehicle do
it "should have a count" do
#not sure what to do here
end
end

describe Motorcycle do
it "should have two tires" do
number_of_tires == 2
end
end