-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,34 @@ | |
Dir.glob("./**/*.rb").each {|f| require f} | ||
|
||
puts "Serenity now!" | ||
|
||
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} | ||
puts automobile | ||
|
||
class Vehicle < Automobile | ||
@@count = Vehicle.count | ||
|
||
def blue_honda_accords | ||
#not sure here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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}