Hey buddy, I feel your pain. I have now just finally solved this exercise, to my immense satisfaction
I purposefully avoid checking other people's answers though until completing the exercises myself; I think it's important to push yourself through the process and get those synapses firing.
Anyway, for your first question:
How does this [method] take two rectangles as arguments?
I had to remind myself of this too when I started this exercise. The answer is, as I think you realise, that it doesn't take
two arguments. It just takes the one argument called, in your example, rec2
which is a Rectangle
object. However, the point that you're missing is that this is a method in your Rectangle class and, as such, it will have been called from one of the two Rectangle
objects that you (should have) instantiated in your main
program. Perhaps you are thinking of it in terms of a function of your main program? Whereas it is actually a method of your Rectangle class.
In other words, the first Rectangle
object - the receiver of the message - is taking the second Rectangle
object into its own intersect
method, to see if they have any intersection. Thus there are two Rectangle
objects with which the comparison can be performed.
Perhaps try looking at pp 137 (Operations on Fractions) and the self
keyword on pp145 again. I think that's where this was first covered.
I hope that helps