On Feb 25, 2009, at 2:54 PM, Ińįki Baz Castillo wrote:

> El MińÓcoles, 25 de Febrero de 2009, Rob Biedenharn escribi
>
>> othervar = myvar.respond_to?(:downcase) ? myvar.downcase : myvar
>>
>> might perform better if the exception to be rescued is expensive to
>> construct only to then be thrown away.  (I don't know if there's any
>> special optimization of the expression form of rescue compared to the
>> block form.)
>
> Really good point. But I've done some benchmarks comparing both  
> approache and
> using "rescue" is ~ 0.30e-5 faster than your approach (even if yours  eems
> more ellegant to me).

It depends on how often myvar.downcase raises an exception. If that's  eally an exceptional occurrence, then just rescuing the occasional  
failure is the Ruby way.

>> It also can hide problems that you won't know that you have. For
>> example,
>>   myvar = nil
>>   othervar = myvar.downcase rescue myvar
>> Did you want to set othervar to nil also?
>
> Not exactly, but myvar could be a Fixnum so othervar would also be a  ixnum.
> But if myvar is a String then I want othervar to be the same String  ut
> downcase.
>
>
> Thanks a lot.
> -- 
> Iki Baz Castillo


de nada

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com