Issue #7216 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Assigned to Closed

Ruby started allowing `clone` on immediate values (true, false, nil, symbol, integer, float) in Ruby 2.4:

```
$ ruby23 -e 'p true.clone'
-e:1:in `clone': can't clone TrueClass (TypeError)
        from -e:1:in `<main>'
$ ruby24 -e 'p true.clone'
true
```

----------------------------------------
Bug #7216: object.c defines clone method for objects that cannot be cloned.
https://bugs.ruby-lang.org/issues/7216#change-80420

* Author: therevmj (Michael Johnson)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
* ruby -v: all versions up to current trunk
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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
>> a.respond_to?(:clone)
=> true
>> a.clone
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.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>