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.
1) Why do these two pieces of code not produce the same results?
2) In the original code, does the variable "record" represent a new
instance of the class?
3) 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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---