Question: 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?

Answer: 
You should use `send` method

```
user.send "#{attribute}=", val

```

If attribute is, say, `:name`, then the line above is equivalent to

```
user.name = val

```
Actually I can do it this way: 

```
[name, address, age].zip(["Name", "Address", 10]).each do |attribute, val|
    user[attribute] = val
end

```

This way works, too