[LRUG] To debug the impossible bug

Tom Stuart tom at therye.org
Wed Aug 3 04:15:38 PDT 2011


On 3 Aug 2011, at 12:12, Matthew Rudy Jacobs wrote:

> 
> 
> On 3 August 2011 12:09, Tom Stuart <tom at therye.org> wrote:
> 
> See page 141 of the pickaxe for this use of case.
> 
> Cheers,
> 
> Tom
> 
> Please enlighten me, then.
> What's the usecase?
> 
> Have never seen this done. 

According to the Pickaxe '[this] form is fairly close to a series of if statements; it lets you list a series of conditions and execute a statement corresponding to the first one that's true."

The code example there is:

case
when song.name == "Misty"
  puts "Not again!"
when song.duration > 120
  puts "Too long!"
when Time.now.hour > 21
  puts "It's too late"
else
  song.play
end

It's pretty ugly, but it's valid Ruby and has nothing to do with the more usual use of case for comparison with === against multiple values.

Cheers,

Tom

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110803/c99690bd/attachment.html>


More information about the Chat mailing list