Hi --

On Wed, 19 Jul 2006, Morton Goldberg wrote:

> I view case without a target as a fancy, more compact, and (IMHO) more 
> readable if-elsif-else block. Because it is more compact and more readable, I 
> prefer it to if-elsif-else and tend to favor it. I may be influenced by some 
> years of doing Common Lisp programming -- I was quite fond of cond.

I'm not sure about its being more compact, unless you've got multiple
conditions in one when.  Compare:

   if a == 1
     ...
   elsif a == 2
     ...
   else
     ...
   end

with:

   case
   when a == 1
     ...
   when a == 2
     ...
   else
     ...
   end

In any, ummmm, case... :-)  I'm glad to be reminded of it.  Do you use
it when things get more deeply nested?


David

>
> On Jul 19, 2006, at 6:42 AM, dblack / wobblini.net wrote:
>
>> Hi --
>> 
>> On Wed, 19 Jul 2006, Morton Goldberg wrote:
>> 
>>> There are two forms of case block and you have sort of mixed them up. 
>>> Either of the following defs of double_it will work. I think the first, 
>>> using a case without a target, is probably what you want, but the second, 
>>> a case with a target (compares target to pattern with ===), can be made to 
>>> work, too.
>> 
>> That's a more thorough answer than mine, since I didn't think of the
>> non-targeted case.  But I realize that I never think of it, because
>> I'm not clear on what its advantages are over a bunch of ifs.  I guess
>> with multiple things you can do:
>>
>>  case
>>  when a == 1, a == 2
>> 
>> etc.
>> 
>> David
>

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
http://www.manning.com/black     => RUBY FOR RAILS (reviewed on
                                     Slashdot, 7/12/2006!)
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
dblack / wobblini.net              => me