# @variable."field#{x}"

**URL:** <https://www.ruby-forum.com/t/variable-field-x/131750>\
**Category:** Rails\
**Created:** [March 12, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/variable-field-x/131750 "2008-03-12T22:45:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 12, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/variable-field-x/131750/1 "2008-03-12T22:45:09Z")

</div>

Ok so could anyone tell me what this is called so I can look it up  
rather posting questions in this forum all the time. I have had to post  
something to learn how to do the following:

Model.send(“field#{x}”)

and

session[“field#{x}”.to\_sym]

now I am trying to do this for variables for example:

@details = RDetails.find(id)  
1.upto(15) do |x|  
@details.???(“field#{x}”)  
end  
@details.save

I don’t even know what to look up. I tried string methods, model  
methods, variable methods…

Thanks in advance

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 12, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/variable-field-x/131750/2 "2008-03-12T22:48:43Z")

</div>

> Ok so could anyone tell me what this is called so I can look it up  
> rather posting questions in this forum all the time. I have had to post  
> something to learn how to do the following:
> 
> Model.send(“field#{x}”)
> 
> and
> 
> session[“field#{x}”.to\_sym]

now I am trying to do this for variables for example:

> @details = RDetails.find(id)  
> 1.upto(15) do |x|  
> @details.???(“field#{x}”)  
> end  
> @details.save
> 
> I don’t even know what to look up. I tried string methods, model  
> methods, variable methods…

What are you trying to do there? Set those fields? Otherwise I doin’t  
see  
what the point is… I’m thinking you maybe want:

@details.send(“field#{x}=”, “some val here”)

That would set all those fields to “some val here”.

-philip

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 12, 2008, 10:54pm UTC](https://www.ruby-forum.com/t/variable-field-x/131750/3 "2008-03-12T22:54:45Z")

</div>

Sorry about that I meant to say:

@details.???(“field#{x}”) = “some value”

And what you said works perfect, that’s exactly what I was trying to do.  
I understood what the .send was doing before, I didn’t realize I could  
also use that to set the values as well using:

@details.send(“field#{x}=”, “some val here”)

Thanks a lot

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 12, 2008, 11:49pm UTC](https://www.ruby-forum.com/t/variable-field-x/131750/4 "2008-03-12T23:49:28Z")

</div>

On Thu, Mar 13, 2008 at 8:54 AM, Chris H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry about that I meant to say:  
> And what you said works perfect, that’s exactly what I was trying to do.  
> I understood what the .send was doing before, I didn’t realize I could  
> also use that to set the values as well using:

As a pointer, ruby is an object oriented language, that means the  
objects pass messages to each other in what we commonly call  
method\_calls.

So, @person.first\_name is a way of sending the ‘first\_name’ message  
to the @person object.

It is equiv to @person.send(:first\_name)

If we wanted to set the first name of a person we could type:

@person.first\_name = ‘Mikel’

But we could also type:

@person.send(:first\_name=, ‘Mikel’)

I would recommend you to get the latest version of the Pickaxe Ruby  
book, it will teach you a lot about these things.

Later

Mikel

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar
