#merge_attributes! - useful to anyone?

I sometimes need to update attributes in mass after initialization without having to save the record (what #update_attributes does). This doesn't seem to be possible in any nice way right now. For example, @obj.attributes.merge!(:field => 'new text') doesn't stick.

I've been experimenting with this method and it seems to do the trick:

module ActiveRecord   class Base     def merge_attributes!(attributes = {})       attributes.each_pair do |att, value|         self.send("#{att}=", value) if self.respond_to?("#{att}=")       end       self.attributes     end   end end

Anyone else find that useful? Or harmful? If it makes sense to others ill patch it up.

Hey,

isn't that the same as doing:

model.attributes = {:subset => :of, :all => :attributes}

Regards, Trevor

isn't that the same as doing:

model.attributes = {:subset => :of, :all => :attributes}

Apparently so, thanks for point it out. I was mistakenly treating attributes as if it was just a hash, not a method.

Thanks!