On Feb 25, 2009, at 2:54 PM, I=F1aki Baz Castillo wrote:

> El Mi=E9rcoles, 25 de Febrero de 2009, Rob Biedenharn escribi=F3:
>
>> othervar =3D 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 =20
> approache and
> using "rescue" is ~ 0.30e-5 faster than your approach (even if yours =20=

> seems
> more ellegant to me).

It depends on how often myvar.downcase raises an exception. If that's =20=

really an exceptional occurrence, then just rescuing the occasional =20
failure is the Ruby way.

>> It also can hide problems that you won't know that you have. For
>> example,
>>   myvar =3D nil
>>   othervar =3D 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 =20=

> Fixnum.
> But if myvar is a String then I want othervar to be the same String =20=

> but
> downcase.
>
>
> Thanks a lot.
> --=20
> I=F1aki Baz Castillo


de nada

-Rob

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