In Rails, I have a class name User, in which I just want to look at :name, :address, :age
I would like to write a piece of code that's something like:
user = User.new
[name, address, age].zip(["Name", "Address", 10]).each do |attribute, val|
user.attribute = val
end
The thing is I don't know how to do it properly, since user.attribute is obviously not a valid line. In other word, is there anyway so that user.attribute gets evaluated as user.name, user.address, user.age depends on the loop?