---2049402039-1706185909-1153308072285
Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-1706185909-1153308072=:2285"

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

---2049402039-1706185909-1153308072285
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

On Wed, 19 Jul 2006, Peñá, Botp wrote:

> fr david:
> # 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
>
> when i use it, i think more in "blocks". it's like "there's a case i'm handling, and the conditions are...".
>
> # In any, ummmm, case... :-)  I'm glad to be reminded of it.  Do you use
> # it when things get more deeply nested?
>
> i combine it w if-else (no elsif)

Here's another interesting usage (with target, but sort of in the
non-targeted spirit):

a = 1

case false
when a == 1
   puts "a is not 1"
when a == 2
   puts "a is not 2"
end

I imagine that would get some readability complaints... :-)  But I
kind of like it because once you get "false" in your head it's easier
to follow, possibly, than a lot of unless/! stuff.


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
---2049402039-1706185909-1153308072285--
---2049402039-1706185909-1153308072285--