From: Robert Klemme Date: 2004-10-27T20:34:06+09:00 Subject: Re: "val.dup rescue val" sloooow "Michael Neumann" 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). I'm not sure though which negative implications the second approach could have. From a usage point of view I'd certainly prefer it. I remember this came up before and I think Matz opted for the first solution: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32556 Kind regards robert