[LRUG] To debug the impossible bug

Viktor Tron viktor.tron at gmail.com
Wed Aug 3 04:23:53 PDT 2011


yes with no value, case becomes a concise way of writing if .. elsif ..  
elsif conditionals
since simon's code is of this type, the bug he gets is a bug you expect  
with the
case nil variant unless somewhere case is redefined to fall back to nil  
with no args
Simon, is this not the 'case'? :)

a little simplified irb for you:

ruby-1.9.2-p180 :001 > case nil when nil then true else false end
  => true
ruby-1.9.2-p180 :002 > case when nil then true else false end
  => false


On Wed, 03 Aug 2011 12:15:38 +0100, Tom Stuart <tom at therye.org> wrote:

>
> 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
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Chat mailing list