Michael Neumann
10/27/2004 3:41:00 PM
On Wed, Oct 27, 2004 at 08:34:06PM +0900, Robert Klemme wrote:
>
> "Michael Neumann" <mneumann@ntecs.de> schrieb im Newsbeitrag
> news:20041027102249.GA4281@miya.intranet.ntecs.de...
> > Hi,
> >
> > I just wanted to tell you that if you do
> >
> > val.dup rescue val
> >
> > somewhere in your program, you should probably switch to:
> >
> > case val
> > when Fixnum, nil, true, false
> > # non dup-able
> > val
> > else
> > val.dup rescue val
> > end
> >
> > which is much faster if you have lots of non-dupable values.
>
> While that works and is efficient, I'd prefer any of these two solutions:
>
> - Remove #dup from types that can't be duped, so we can check with
> respond_to?
>
> - Have #dup return self in these cases (immutable instances anyway).
Yes that seems reasonable, as e.g. #freeze does not raise an error on
these kind of objects, too.
Regards,
Michael