Skip to content
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
20 changes: 20 additions & 0 deletions models/automobile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Automobile

@number_of_wheels
Copy link
Member

Choose a reason for hiding this comment

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

In Ruby, you don't need to pre-declare your instance variables like this. You can just start using them later

@color
@make
@model
@year

def set_number_of_wheels
Copy link
Member

Choose a reason for hiding this comment

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

This set_number_of_wheels would only be executed when you call it. It might be better to:

def initialize
  @number_of_wheels = 4
end

Then, it would get executed when you create the Automobile object.

@number_of_wheels = 4
end

def update(hsh)
@color = {hsh[:color]}
Copy link
Member

Choose a reason for hiding this comment

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

You don't want to wrap the hsh with {} when you access it. you'll want to:

@color = hsh[:color]

On naming --- the convention here would be to spell out hash. Though, a further convention in ruby is to name this "args" or "params"

(don't ask me why we don't spell out arguments. too long, prolly).

@make = {hsh[:make]}
@model = {hsh[:model]}
@year = {hsh[:year]}
end

end
8 changes: 8 additions & 0 deletions models/motorcycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Motorcycle < Vehicle

def set_number_of_wheels
@number_of_wheels = 2
end


end
3 changes: 3 additions & 0 deletions models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Vehicle < Automobile

end