On Apr 26, 2007, at 8:04 AM, Bob Showalter wrote:
> On 4/26/07, Ruby Quiz <> wrote:
>
>> block[prefix] if @@words.nil? || @@words.include?(prefix)
>
> I didn't understand that when I first saw it. I kept looking for
> "yield". Now I see that "block[prefix]" is the same as "yield prefix".
> Or are there differences?
There are two ways to handle blocks passed to methods. One is to
yield to it as needed. Another is to ask Ruby to wrap it up in a
Proc object for you.
yield isn't ideal in this case because the method recurses and we
need to use the same block for all of those invocations. By asking
for the object we have it to pass along.
Does that make sense?
>> The next line is a usage statement printed by abort(). We don't
>> see that method
>> too often in quiz solutions, but it prints a message to STDERR,
>> when provided,
>> and then terminates the program.
>
> That's an old Perl'er used to "die()". raise() is so brutal for this
> kind of thing :~)
I liked it. I just had to look it up, so I thought I would share.
James Edward Gray II