Feature #9487

Add #dup?, #dup! and #clone? and #clone!

Added by Atlas Prime about 1 year ago. Updated about 1 year ago.

[ruby-core:60511]
Status:Rejected
Priority:Normal
Assignee:Yukihiro Matsumoto

Description

Some objects can't use #dup or #clone b/c they are singleton, like Integer. So an error is raised if one tries.

> 5.dup
TypeError: can't dup Fixnum

It would helpful if there was an easy way to check if this is so on an arbitrary object without having to go through the overhead of rescuing the TypeError. e.g.

if o.dup?
  x = o.dup
  ...

Even more convenient in some cases would not having to worry about it at all. If the object can't be duplicated or cloned then just return the object itself.

> 5.dup!
5

The same for #clone with #clone? and #clone!.

History

#1 Updated by Yukihiro Matsumoto about 1 year ago

  • Status changed from Open to Rejected
  • Assignee set to Yukihiro Matsumoto

Nice try. But dup! and clone! are not following the naming convention (adding ! to more dangerous version).
We are waiting for other naming candidates.

Matz.

Also available in: Atom PDF