Uh oh!
There was an error while loading. Please reload this page.
Panda Assignment submission. - #20
Conversation
There was a problem hiding this comment.
a method that ends in "?" should return a true/false
jwo
commented
Feb 4, 2014
Good first step at a Panda submission -- let me know if you have any questions on it, and be sure to ping me "@jwo" when you push new code for this pull request. |
codeblahblah
commented
Feb 4, 2014
Gotcha. On 4 February 2014 17:19, Jesse Wolgamott notifications@github.com wrote:
"When you are tired of being yourself then you can be ordinary." - dudu |
jwo
commented
Feb 4, 2014
You should type “@jwo" On Tuesday, February 4, 2014 at 10:21 AM, drammopo wrote:
|
codeblahblah
commented
Feb 4, 2014
Corrections made. |
jwo
commented
Feb 4, 2014
Looks good. The only thing missing is:
So, I should be able to: auto=Automobile.new(x,y,z)auto.update(a,b,c) |
codeblahblah
commented
Feb 4, 2014
Added update method to the class. |
There was a problem hiding this comment.
what does purs auto.model output? Is it what you expect?
codeblahblah
commented
Feb 4, 2014
jwo
commented
Feb 4, 2014
What you want to do is overwrite, if the arg is there, otherwise you leave it. This is the most common form of that expression @model=new_args[:model]ifnew_args[:model]You could also use fetch with a default to achieve a cleaner, but possibly harder to understand look: @model=new_args.fetch(:model,@model) |
codeblahblah
commented
Feb 4, 2014
For now I'll use: @model=new_args[:model]ifnew_args[:model]The correction has been made. |
codeblahblah
commented
Feb 4, 2014
Well spotted. |
jwo
commented
Feb 4, 2014
Awesome 🎉 ! |
codeblahblah
commented
Feb 6, 2014
@jwo Automobiles are not counted when created? All other types are. Why is that? |
jwo
commented
Feb 6, 2014
Oh, should have caught that. Call "super" in your subclass, and it'll call the initialize in your superclass. So when auto is initialized, if you call super, it will call initialize of Vehicle as well. On Thu, Feb 6, 2014 at 11:39 AM, drammopo notifications@github.com
|
codeblahblah
commented
Feb 6, 2014
I had that in my original code and but got: See snippet below definitialize(args)@color=args[:color]@make=args[:make]@model=args[:model]@year=args[:year]superend |
jwo
commented
Feb 6, 2014
Ahh try super() That's tell ruby to only call it with 0 arguments. On Thu, Feb 6, 2014 at 11:55 AM, drammopo notifications@github.com
|
codeblahblah
commented
Feb 6, 2014
Working now. |
jwo
commented
Feb 7, 2014
It would seem that the following are not needed Vehicle.register(self)Automobile.build_car(args)And you don't need both a |
jwo
commented
Feb 7, 2014
To clarify, this is what I'm after: classAutomobiledefinitialize(args)@color=args[:color]@make=args[:make]@model=args[:model]@year=args[:year]Vehicle.register(self)Automobile.build_car(args)super()enddefself.build(args)auto=Automobile.build(args)@@vehicles << autoautoendenddescribeAutomobiledoit"records the auto when I build it"doauto=Automobile.buildexpect(Automobile.all_autos).toinclude?(auto)endend |
codeblahblah
commented
Feb 7, 2014
@jwo Please expand on the Also can you call self.build on itself as per your example above? defself.build(args)auto=Automobile.build(args)@@vehicles << autoautoend |
jwo
commented
Feb 7, 2014
Yes it's similar.
Yes, why do you think you couldn't? On Fri, Feb 7, 2014 at 1:37 PM, drammopo notifications@github.com wrote:
|
codeblahblah
commented
Feb 7, 2014
@jwo Hmmmm. I see the error in my thinking. classAutomobiledefinitialize(args)@color=args[:color]@make=args[:make]@model=args[:model]@year=args[:year]Automobile.build(args)super()enddefself.build(args)auto=Automobile.build(args)@@vehicles << autoautoendenddescribeAutomobiledoit"records the auto when I build it"doauto=Automobile.buildexpect(Automobile.all_autos).toinclude?(auto)endend |
jwo
commented
Feb 7, 2014
Here is what I want in this discussion. You don't register when you call classAutomobiledefinitialize(args)@color=args[:color]@make=args[:make]@model=args[:model]@year=args[:year]super()endYou register if someone calls That makes In the same way, in Rails, you can call |
codeblahblah
commented
Feb 7, 2014
@jwo The latest code is up. |
jwo
commented
Feb 7, 2014
here's what I'd love to see Automobile.count=>0Automobile.build(model: 'Mustang',color: 'Red',make: 'Ford',year: 2007)Automobile.count=>1 |
codeblahblah
commented
Feb 7, 2014
@jwo |
jwo
commented
Feb 7, 2014
Well, this is an exercise in showing the difference between class methods and initialization methods. In a production system, you don't want an initializer to have side effects. You should be able to create objects without effects. Then, you can call different methods to persist or otherwise affect them. On Fri, Feb 7, 2014 at 3:41 PM, drammopo notifications@github.com wrote:
|
codeblahblah
commented
Feb 7, 2014
@jwo defself.build(args)auto=Automobile.new(args)@@vehicles << auto@@auto << autoautoend |
jwo
commented
Feb 7, 2014
awesome! On Fri, Feb 7, 2014 at 3:47 PM, drammopo notifications@github.com wrote:
|
codeblahblah
commented
Feb 7, 2014
@jwo Used the Rails operation(s) all the time without understanding what was going on under the hood. Thanks for this! |
jwo
commented
Feb 7, 2014
That is literally the coolest, best compliment you can give me for this course 🎉 😄 Do you approve for me to use it in a testimonial? |
codeblahblah
commented
Feb 7, 2014
Definitely. Midnight all ready. Gotta catch some Zzzz. |
codeblahblah
commented
Feb 8, 2014
@jwo I made a pun related to cars without realising. |
There was a problem hiding this comment.
I would rather you use "let" instead of @auto.
Instead of
before:eachdo@auto=Automobile.new(model: 'Mustang',color: 'Red',make: 'Ford',year: 2007)endI would
let(:auto){Automobile.new(model: 'Mustang',color: 'Red',make: 'Ford',year: 2007)}Then later,
auto.shouldbe_an_instance_ofAutomobilejwo
commented
Feb 11, 2014
Test suite looks most excellent! I think you have this down (and also the longest pull request ever :) ) |
codeblahblah
commented
Feb 11, 2014
@jwo Awesome! |
codeblahblah
commented
Feb 11, 2014
@jwo Am I testing the Vehicle#search correctly? |
jwo
commented
Feb 11, 2014
Can you point me to where you are testing it? |
codeblahblah
commented
Feb 11, 2014
@jwo /spec/vehicle_spec.rb |
jwo
commented
Feb 11, 2014
Going to say no, vehicle_spec looks extremely bare. |
codeblahblah
commented
Feb 11, 2014
@jwo Apologies. |
There was a problem hiding this comment.
This seems like a fine search. It doesn't cover all functionality though.
I might like it if it were the following, where you are more assertive about the results.
Vehicle.search(color: "blue",model: "honda").shouldeq([auto])
Created a panda.rb file in the Models directory.