Bug #7216

object.c defines clone method for objects that cannot be cloned.

Added by Michael Johnson almost 3 years ago. Updated over 2 years ago.

Assignee:Yukihiro Matsumoto
ruby -v:all versions up to current trunk Backport:


As the subject says, in object.c, the clone method is defined and then special cased for certain object types. The end result is that all respond_to?(:clone) returns true for all objects, but then thows an fatal error in some cases. Here is an appropriate example:

a = true
=> true
=> true
TypeError: can't clone TrueClass
from (irb):3:in `clone'
from (irb):3

Ultimately, the objects that do no respond to 'clone' should have it removed so that the respond_to? method returns false.


#1 Updated by Yusuke Endoh almost 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Akira Tanaka
  • Target version set to 2.0.0

Akr-san, what do you think?

Yusuke Endoh mame@tsg.ne.jp

#2 Updated by Akira Tanaka almost 3 years ago

2012/11/5 mame (Yusuke Endoh) mame@tsg.ne.jp:

Issue #7216 has been updated by mame (Yusuke Endoh).

Akr-san, what do you think?

It may be good idea.

The root problem is that Liskov substitution principle is violated
between Object and TrueClass.
(Object is clonable but its subclass, TrueClass, is not.)

So, such unprincipled classes may have responsibility to
undefine/unimplement methods which don't work.

I feel it's better to ask matz.
Tanaka Akira

#3 Updated by Thomas Sawyer over 2 years ago

This is true for class method #allocate too.

#4 Updated by Yusuke Endoh over 2 years ago

  • Assignee changed from Akira Tanaka to Yukihiro Matsumoto
  • Target version changed from 2.0.0 to next minor

Also available in: Atom PDF