[LRUG] To debug the impossible bug
Jordi Noguera Leon
jordinoguera83 at gmail.com
Wed Aug 3 04:28:52 PDT 2011
I'd rather use:
def some_other_method
return foo.whatever if foo
return bar.whatever if bar
"some message"
end
On 3 August 2011 12:23, Viktor Tron <viktor.tron at gmail.com> wrote:
> 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/
>
> ______________________________**_________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/**listinfo.cgi/chat-lrug.org<http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110803/913fe9af/attachment-0003.html>
More information about the Chat
mailing list