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

Feature: Panda and Tiger #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ThePomodoro
Copy link

Hi Jesse. I completed the Panda and Tiger assignments, but was stumped by the Eagle one as I couldn't see a discussion of class objects or inheritance in video 6 or any of the previous videos I saw.

You asked:
"1. Create a class variable (@@) in the Vehicle that tracks all vehicles mde"
Does mde mean model?

I had created a class 'Vehicle' that the other classes inherited from, but vehicle didn't have a model variable, and I wasn't sure whether to recreate one, given that there was already one in automobile. What's the best approach?

Will begin watching first 3 episodes of TDD course next.

@jwo
Copy link
Member

jwo commented Jan 13, 2014

Does mde mean model?

No, it means "made", as in manufactured.

@@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Member

Choose a reason for hiding this comment

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

Please add these .idea to your .gitignore file

(and if that sounds like klingon to you, let me know)

@jwo
Copy link
Member

jwo commented Jan 13, 2014

I had created a class 'Vehicle' that the other classes inherited from, but vehicle didn't have a model variable, and I wasn't sure whether to recreate one, given that there was already one in automobile. What's the best approach?

since Automobile will inherit from Vehicle, you should move the "model" variable up into Vehicle. There, both Vehicle and Automobile will have access to it.

@jwo
Copy link
Member

jwo commented Jan 13, 2014

For example, check this out: http://rubyfiddle.com/riddles/70ebf ... The Vehicle has model variable, but automobile has access to it.

class Vehicle

  attr_reader :model
  def initialize(args)
    @model = args.fetch(:model)
  end
end

class Automobile < Vehicle

  attr_reader :year
  def initialize(args)
    super
    @year = args.fetch(:year)
  end
end

car = Automobile.new(year: 1991, model: "Yugo")
car.model

@ThePomodoro
Copy link
Author

Hi Jesse. I made some changes on the Episode 6 exercise but I'm stuck on a
few things.

Firstly and most importantly I can't work out how to send you a pull
request. I committed my changes and pushed them:

git commit -am "Feature: Redid Panda-Tiger"
git push origin master

and the file changes show up in my repository, but I can't figure out how
to make a pull request. The normal options don't show up. Am attaching
screen shot.

Secondly, In my code, I just pulled all the variables from the Automobile
class into Vehicle, leaving nothing in Automobile. Then I called

super(args)

inside the initialize and update methods in automobile. The problem is that
I have :tires in Vehicle, and just to see if it would work, I decided that
I didn't want to give that to Automobile. When I pass the hash without
:tires to automobile it tells me that:

Episode6/models/Vehicle.rb:5:in `fetch': key not found: :tires (KeyError)

How can I easily pass only some of the variables into a child class method
that's inheriting the ancestor's method, even though the ancestor expects
them all?

Best wishes,

Danny Bradbury
Freelance writer and editor
Web: www.wordherder.net
Twitter: @dannybradbury
Skype: dannybradbury
Tel: +1 604 757 4566

On 13 January 2014 06:45, Jesse Wolgamott [email protected] wrote:

For example, check this out: http://rubyfiddle.com/riddles/70ebf ... The
Vehicle has model variable, but automobile has access to it.

class Vehicle

attr_reader :model
def initialize(args)
@model = args.fetch(:model)
endend
class Automobile < Vehicle

attr_reader :year
def initialize(args)
super
@year = args.fetch(:year)
endend
car = Automobile.new(year: 1991, model: "Yugo")car.model


Reply to this email directly or view it on GitHubhttps://github.com//pull/17#issuecomment-32174632
.

@jwo
Copy link
Member

jwo commented Jan 20, 2014

On Friday, January 17, 2014 at 10:55 PM, ThePomodoro wrote:

Hi Jesse. I made some changes on the Episode 6 exercise but I'm stuck on a
few things.
Hi Ya!

Firstly and most importantly I can't work out how to send you a pull
request. I committed my changes and pushed them:

git commit -am "Feature: Redid Panda-Tiger"
git push origin master

and the file changes show up in my repository, but I can't figure out how
to make a pull request. The normal options don't show up. Am attaching
screen shot.
When you are updating an existing pull request, it will automatically use the latest commits, and the reason we leave the pull requests open. Simply push, and make a comment:

@jwo I’ve updated the code for x,y,z"

Secondly, In my code, I just pulled all the variables from the Automobile
class into Vehicle, leaving nothing in Automobile. Then I called

super(args)

inside the initialize and update methods in automobile. The problem is that
I have :tires in Vehicle, and just to see if it would work, I decided that
I didn't want to give that to Automobile. When I pass the hash without
:tires to automobile it tells me that:

Episode6/models/Vehicle.rb:5:in `fetch': key not found: :tires (KeyError)

How can I easily pass only some of the variables into a child class method
that's inheriting the ancestor's method, even though the ancestor expects
them all?
let’s say you want to set @Tires if, and only if, a “tires” is present in a hash

@Tires = args[:tires] if args[:tires]

An alternative syntax, where we set it to itself if the key doesn’t exist

@Tires = args.fetch(:tires, @Tires)

Best wishes,

Danny Bradbury
Freelance writer and editor
Web: www.wordherder.net (http://www.wordherder.net)
Twitter: @dannybradbury
Skype: dannybradbury
Tel: +1 604 757 4566

On 13 January 2014 06:45, Jesse Wolgamott <[email protected] (mailto:[email protected])> wrote:

For example, check this out: http://rubyfiddle.com/riddles/70ebf ... The
Vehicle has model variable, but automobile has access to it.

class Vehicle

attr_reader :model
def initialize(args)
@model = args.fetch(:model)
endend
class Automobile < Vehicle

attr_reader :year
def initialize(args)
super
@year = args.fetch(:year)
endend
car = Automobile.new(year: 1991, model: "Yugo")car.model


Reply to this email directly or view it on GitHubhttps://github.com//pull/17#issuecomment-32174632
.


Reply to this email directly or view it on GitHub (#17 (comment)).

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