On Jun 23, 2007, at 12:06 AM, Giles Bowkett wrote:

>> > original_obj.attributes.each do |attr, value|
>> >  new_obj.update_attribute(attr.to_sym, value)
>> > end
>>
>> You don't even need #to_sym :-). Note that rewrite has the side-
>> effect of actually saving those attributes of new_object in the
>> database, whereas the original assignments didn't. Perhaps that's OK
>> though.
>
> Well, if you've got validation callbacks (e.g.
> validates_uniqueness_of) this version could blow up on that.

Not really, update_attribute() bypasses validations by default, it's  
written like this:

   send(name.to_s + '=', value)
   save(false)

> Also - I didn't realize these methods came from ActiveSupport. Doh.
> The original ran in pure Ruby without Rails - it'd probably be ideal
> to implement the solution in pure Ruby.

Yeah, except for the call to attributes(), which is a Railism. In  
fact I thought this thread belonged to the Rails mailing list because  
of that.

-- fxn