ruby on rails - How do I use an array of object parameters to set the value of -


i have array of parameters shared between 2 objects.

attributes = [:name, :category, :value] 

the first object has parameters set. pass same values onto second object.

how do this?

my initial thought use:

attributes.each |attribute|     @object_2.(attribute) = object_1.(attribute) end 

i tried putting attribute variable inside of "#{attribute}" still did not work.

i've tried number of different solutions no help, , googling answer past hour has not helped.

some of results seemed suggest accomplish looking send() method, attempts use did not help.

attributes.each |attribute|     @object_2.send(attribute) = object_1.send(attribute) end 

if question has been answered before (i not find solution extensive searching) please point me towards solution.

thanks.

attributes.each |attribute|     @object_2.send("#{attribute}=", object_1.send(attribute)) end 

Comments