On 2/17/07, Stefan Rusterholz <apeiros / gmx.net> wrote:

> As I said, I consider it a minor glitch. Of course you can work around
> the problem, but a workaround is still only a workaround. IMHO the
> "correct" way to do what you do above would be:
>
> b = a.respond_to?(:dup) ? a.dup : a

You're right, this is a better way.   I don't consider it a work
around.  I consider it to be accounting for a language implementation
detail.  (In that some objects cannot inherently be dup'ed)

> If you have concerns about that beeing not as fast as rescuing your code
> would still work (the raised exception would just be different).
> Since that is my oppinion I posted this to the ML to see what other
> oppinions about that are.
> Besides, your above code assumes that the only reason a dup fails is due
> to the singleton-immutables, what if dup fails due to another reason?
> With your above code you'll have a happy time tracking the bug as a
> potential exception will never be raised.

If I wrote that code, I'd assume it was behaving as I intended, and be
sure to have tests to show it, but truthfully, the code you mentioned
is better.

It's valid to consider that if you are dup'ing objects that shouldn't
be duped 'by accident', then perhaps something has gone wrong in your
program design.