Ruby defines #clone
in Object.
To my suprise, some classes raise Exceptions when calling it.
I found NilClass, TrueCla
I don't think there is a formal list, at least unless you count reading the source. The reason 2) doesn't work is because of an optimization applied to Fixnums. They are stored/passed internally as their actual values (so are true, false and nil), and not as pointers. The naive solution is to just have 42.clone
return the same 42
, but then the invariant obj.clone.object_id != obj.object_id
would no longer hold, 42.clone
wouldn't actually be cloning.