All,
I am attempting to patch ActiveRecord::Base#clone (what I think the bug
is can be another thread), and I am having difficulty navigating the
Ruby magic.
The last 3 lines in clone() are:
self.class.new do |record|
record.send :instance_variable_set, ‘@attributes’, attrs
end
I try to replace it with the code below - basically pulling the
assignment of the @attributes hash outside of the new instantiation.
newobj = self.class.new
newobj.instance_variable_set(’@attributes’, attrs)
and it breaks three tests.
-
Why do these two pieces of code not produce the same results?
-
In the original code, does the variable “record” represent a new
instance of the class? -
Unfortunately, I can’t even tell if self.class.new is calling the
class method “new” or the instance method “new”. Looks like the
class method takes a block and the instance method doesn’t. It makes
sense to me that my code is not working if the original code deals with
the class method. But then I don’t really understand what that original
code returns.
Any help would be appreciated.
Thanks,
Wes