-
Notifications
You must be signed in to change notification settings - Fork 22
Panda, Tiger, and Eagle #12
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
Open
meltar
wants to merge
5
commits into
RubyoffRails:master
Choose a base branch
from
meltar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0827b33
Panda complete with TDD
meltar eb3370e
Tiger complete with TDD!
meltar 195e7d7
Tiger complete with TDD - and all the files needed
meltar 09c8985
Eagle complete with TDD and some refactoring/improvements
meltar b89dc17
changed Vehicles to vehicles and used the Vehicle attr_reader variables
meltar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| require_relative "Vehicle" | ||
|
|
||
| class Automobile < Vehicle | ||
|
|
||
| def self.number_of_wheels | ||
| @wheels = 4 | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| require_relative "Vehicle" | ||
|
|
||
| class Motorcycle < Vehicle | ||
|
|
||
| def self.number_of_wheels | ||
| @wheels = 2 | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| class Vehicle | ||
|
|
||
| @@Vehicles = [] | ||
|
|
||
| def self.get_favorite_combo | ||
| veh = @@Vehicles.select { |i| i.color == "blue" && | ||
| i.make == "Honda" && i.model == "Accord" } | ||
| end | ||
|
|
||
| def self.reset | ||
| @@Vehicles = [] | ||
| end | ||
|
|
||
| def self.number_of_wheels | ||
| @wheels = nil | ||
| end | ||
|
|
||
| def self.Vehicles | ||
| @@Vehicles | ||
| end | ||
|
|
||
| attr_reader :color, :make, :model, :year | ||
| def initialize (hash={}) | ||
| @@Vehicles << self | ||
| @color = hash.fetch(:color) | ||
| @make = hash.fetch(:make) | ||
| @model = hash.fetch(:model) | ||
| @year = hash.fetch(:year) | ||
| end | ||
|
|
||
| def update (hash={}) | ||
| @color = hash.fetch(:color) | ||
| @make = hash.fetch(:make) | ||
| @model = hash.fetch(:model) | ||
| @year = hash.fetch(:year) | ||
| end | ||
|
|
||
| def color | ||
|
Member
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. for these, I prefer to create the 'getter' in ruby like so: attr_reader :colorThis will be functionality equivalent to the def color
@color
endAnd you can simplify: attr_reader :color, :make, :model, :year |
||
| @color | ||
| end | ||
|
|
||
| def make | ||
| @make | ||
| end | ||
|
|
||
| def model | ||
| @model | ||
| end | ||
|
|
||
| def year | ||
| @year | ||
| end | ||
|
|
||
| def to_s | ||
| "#{year} #{color} #{make} #{model}" | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| require "rspec" | ||
| require_relative "../models/automobile" | ||
|
|
||
| describe Automobile do | ||
|
|
||
| it "should have four wheels" do | ||
| Automobile.number_of_wheels.should eq(4) | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| require "rspec" | ||
| require_relative "../models/motorcycle" | ||
|
|
||
| describe Motorcycle do | ||
|
|
||
| it "should have two wheels" do | ||
| Motorcycle.number_of_wheels.should eq(2) | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| require "rspec" | ||
| require_relative "../models/vehicle" | ||
|
|
||
| describe Vehicle do | ||
|
|
||
| before(:each) do | ||
| Vehicle.reset | ||
| end | ||
|
|
||
| it "should have four wheels" do | ||
| Vehicle.number_of_wheels.should eq(nil) | ||
| end | ||
|
|
||
| it "class should keep track of the vehicles made" do | ||
| Vehicle.Vehicles.should_not be(nil) | ||
| Vehicle.Vehicles.count.should eq(0) | ||
| veh = Vehicle.new(color: "white", make: "Honda", model: "Accord", year: "2002") | ||
| Vehicle.Vehicles.count.should eq(1) | ||
| end | ||
|
|
||
|
|
||
| it "should take input to describe the automobile" do | ||
| auto = Vehicle.new(color: "black", make: "Honda", model: "Accord", year: "2002") | ||
| auto.color.should eq("black") | ||
| auto.make.should eq("Honda") | ||
| auto.model.should eq("Accord") | ||
| auto.year.should eq("2002") | ||
| end | ||
|
|
||
| it "should allow an update to the automobile" do | ||
| auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") | ||
| auto.update(color: "red", make: "Honda", model: "Accord", year: "2002") | ||
| auto.color.should eq("red") | ||
| auto.make.should eq("Honda") | ||
| auto.model.should eq("Accord") | ||
| auto.year.should eq("2002") | ||
| end | ||
|
|
||
| it "should filter the vehicles list to only show blue Honda Accords" do | ||
| auto1 = Vehicle.new(color: "blue", make: "Honda", model: "Accord", year: "2002") | ||
| auto2 = Vehicle.new(color: "blue", make: "Honda", model: "Accord", year: "2005") | ||
| auto3 = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") | ||
| results = Vehicle.get_favorite_combo | ||
| results.count.should eq(2) | ||
| end | ||
|
|
||
| it "should allow the class to be reset" do | ||
| auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") | ||
| Vehicle.reset | ||
| Vehicle.Vehicles.count.should eq(0) | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you should keep the naming for this class variable the same as other variables:
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.
Oops. I should have caught that. My Vehicles variable was bothering me, and I think this is why.