From: Bala Paranj Date: 2007-06-22T04:15:50+09:00 Subject: Re: undefined method 'a=' when initializing an object I have an array that contains list of attributes of a ActiveRecord object. I have another array that contains list of values for those attributes. So for a Foo object, attributes_list = ["first_name", "last_name"] values_list = ["Bugs", "Bunny"] I have instantiated the class by: class_name = class_string.constantize obj = class_name.new Then I just loop up through those arrays and set values to the attributes: obj.attribute1 = value1 I get: undefined method `attribute1=' for # How do I set values for the attributes? TIA. On 6/21/07, Gregory Brown wrote: > On 6/21/07, Bala Paranj wrote: > > > When I run eval("obj.#{a} = #{value}"), I get the undefined method > > 'a=' error message. Please help. TIA. > > Please do not use eval() unless you have a good reason to! It's very > dangerous if you're not careful. > > What you're looking for is: > > obj.send("#{a}=", value) > > Still, you're going to need to show more code for people to be able to > help you. Where is a being defined, what is obj? > >