Completed Homework #3
Conversation
|
Nicely done! What do you mean by "since I found out that variables in your program aren't available in IRB" ? |
|
Thanks! To answer your question, what I wanted to do was instantiate a FoodBarge object within zoo.rb and assign it an array of hashes containing each animals foods, so I could quickly reference it. For example, But I soon found out that when I tried to call the variable in IRB it was nil. |
|
Ahh, ok... When you go into IRB, if you say Then it will execute everything in zoo... And if you have the @foodbarge = Foodbarge.new, then you'll be good to go. In a real-life program, you'd probably have something like: Then in irb, you'd: |
|
Nice. That makes much more sense whereby all the animals, food_barge, zookeepers are all instances within the zoo class. |
I managed to complete the first assignment without any issues and writing the tests weren't a problem.
I got a little confused with the extra credit exercises.
For extra credit 1. I just created a Food class and converted the symbols to instances of Food. Not sure if this is what you were thinking?
For extra credit 2. I was also a little unsure as to what to do with a FoodBarge. I ended up creating a FoodBarge class, assuming that @foodbarge would be created as a new instance in IRB (since I found out that variables in your program aren't available in IRB). Now, when you call food_for on a FoodBarge object, it should check which class of animal it is dealing with and return an array of acceptable foods names' as strings.
So in IRB it'll be something like:
@foodbarge = FoodBarge.new
panda = Panda.new
food = @foodbarge.food_for(panda)
panda.feed(food)
When you call feed on panda it should go through the array of foods and if it likes? it it'll add to the meal count etc.
I got quite confused with writing the tests so I ended up writing the code and then trying to go back and write more tests. I guess my problem now is that I don't know what to test for exactly as well as being a little 'iffy' on rspec syntax.