Skip to content

Conversation

@var114
Copy link

@var114 var114 commented Nov 19, 2013

No description provided.

Copy link
Member

Choose a reason for hiding this comment

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

In RSpec, it has cool matchers that I like to point out. You could rewrite this methot as:

Vehicle.wheels.should be_nil

@jwo
Copy link
Member

jwo commented Nov 19, 2013

Looks pretty great!

The only thing I wasn't 100% on was the self.wheels --- In it, you are setting a variable and returning it.

class Vehicle
  @@wheels = 0

  def self.wheels
    @@wheels
  end
end

Then in your motorcycle, you can override the @@wheels

class Motorcylcle < Vehicle
  @@wheels = 2
end

Vehicle.wheels
=> 0

Motorcycle.wheels
=> 2

OR, possibly event simpler (but without using class variables):

class Vehicle
  WHEEL_COUNT = 0

  def self.wheels
    WHEEL_COUNT
  end
end
class Motorcycle < Vehicle
  WHEEL_COUNT = 2
end

puts Motorcycle.wheels
=> 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants