Before this commit, clone gave different results depending on whether the original object had an attached singleton class or not.
Consider the following setup:
class Foo; end Foo.singleton_class.define_method(:foo) {} obj = Foo.new obj.singleton_class if $call_singleton clone = obj.clone
When $call_singleton = false, neither obj.singleton_class.singleton_class nor clone.singleton_class.singleton_class own any methods.
However, when $call_singleton = true, clone.singleton_class.singleton_class would own a copy of foo from Foo.singleton_class, even though obj.singleton_class.singleton_class does not.
The latter case is unexpected and results in a visibly different clone, depending on if the original object had an attached class or not.
Fix singleton class cloning
Before this commit,
clonegave different results depending on whether the original objecthad an attached singleton class or not.
Consider the following setup:
When
$call_singleton = false, neitherobj.singleton_class.singleton_classnorclone.singleton_class.singleton_classown any methods.However, when
$call_singleton = true,clone.singleton_class.singleton_classwould own a copy offoofromFoo.singleton_class, even thoughobj.singleton_class.singleton_classdoes not.The latter case is unexpected and results in a visibly different clone, depending on if the original object
had an attached class or not.
Co-authored-by: Ufuk Kayserilioglu ufuk.kayserilioglu@shopify.com