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 seems 
more ellegant to me).


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


Thanks a lot.


-- 
Iki Baz Castillo