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 approache a=
nd=20
using "rescue" is ~ 0.30e-5 faster than your approach (even if yours seems=
=20
more ellegant to me).


> 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 Fixnum=
=2E=20
But if myvar is a String then I want othervar to be the same String but=20
downcase.


Thanks a lot.


=2D-=20
I=F1aki Baz Castillo