jeffz_2002
1/3/2007 6:04:00 PM
Thanks David and Andre, I finally get it, and Andre, you're right about
the nil/false idea in your response to my reponse.
For anyone else following this thread, the idea is:
- The first time the method is called, @foo doesn't exist.
- @foo doesn't exist, so it's assigned a single-element array
containing the value returned by the call to the private aliased
original method. This value can be anything, including an array,
false, nil, whatever.
- The 0th array element, which is just the return value of the function
call, is returned.
- The next time the method is called, @foo still exists, and is still a
single-element array. We again return the 0th element, which is the
answer.
The [0] is used because the result is stored in an array ... this gets
around the original method returning nil or false, which would end up
in a second call to the function, had we just naively used @foo ||=
foo( *args, &block )..
Thanks again. It's pretty obvious, actually ... sigh.
Funny, I still don't feel well on my way to mastery. I actually feel
dumber, in a way.
jz