On Sep 2, 2006, at 4:45 PM, Martin DeMello wrote:

> On 9/2/06, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
>>
>> Going further OT, but you can omit the "true":
>>
>> result = case
>> when a == b: 0
>> when a < b  : 1
>> when a > b  : -1
>> end
>
> Why does this work?
>
Cause ruby is cool like that? ;)

There are actually two forms of case, the first being

case x
when y
  ...
when z
  ...
else
  ...
end

which is equivalent to:

if y === x
   ...
elsif z === x
   ...
else
   ...
end

and
case
  when cond1
   ...
  when cond2
   ...
  else
   ...
end

which is equivalent to

if cond1
   ...
elsif cond2
   ...
else
   ...
end


> martin
>