From: "ellipsoid (Andrew Northrop)" Date: 2013-06-05T16:26:27+09:00 Subject: [ruby-core:55311] [ruby-trunk - Feature #8494][Open] Safe method for defensive copies. alternative to 'dup' Issue #8494 has been reported by ellipsoid (Andrew Northrop). ---------------------------------------- Feature #8494: Safe method for defensive copies. alternative to 'dup' https://bugs.ruby-lang.org/issues/8494 Author: ellipsoid (Andrew Northrop) Status: Open Priority: Normal Assignee: Category: core Target version: As a developer I want a simple method that will return a "safe" version of my object So I can make defensive copies easily and safely This is related to issue 1844: http://www.ruby-forum.com/topic/3650325 I have tried using 'dup' to make defensive copies, but 'dup' throws an exception when used on a Fixnum and the like, because these values aren't copyable. I tried to throw a "respond_to?" around the call, but that didn't work, since these classes still technically respond to 'dup'. It looks like there's an extension method to do this (http://ruby-doc.org/gems/docs/c/core_ex-0.6.6.3/CoreEx/TryDup.html), but I don't see why this isn't in the core language. It seems like a common enough use case. As far as naming, 'dup' is really just the means to an end. A more meaningful name would be something like 'defensive', or 'safe'. Although 'try_dup' like the extension method would also work. Any chance of something like this making it in to Ruby core? -- http://bugs.ruby-lang.org/