# What does the send() method do on a model object?

**URL:** <https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794>\
**Category:** Rails\
**Created:** [March 14, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794 "2006-03-14T18:54:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 14, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794/1 "2006-03-14T18:54:17Z")

</div>

All,

I did a scaffold for a model and I ended up with this code in  
list.rhtml:

\<% for column in TargetList.content\_columns %\>

\<%=h target\_list.send(column.name) %\>  
\<% end %\>

Where is the “send” method and what does it do?

I can’t find it on ActiveRecord::Base? I assume that it returns a  
value based on the column id but I can’t find any documentation on it.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 14, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794/2 "2006-03-14T19:00:30Z")

</div>

Hi –

On Tue, 14 Mar 2006, Wes G. wrote:

> I can’t find it on ActiveRecord::Base? I assume that it returns a  
> value based on the column id but I can’t find any documentation on it.

send sends a message to an object. In this case, you’re sending the  
name of the column to the object in target\_list.

Sending a message is basically equivalent to calling a method. But  
since you don’t know the name(s) of the methods in advance (they’re in  
the columns), you use send to generalize the process.

It’s a built-in Ruby facility; it’s used in many programs and systems,  
not just Rails.

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” chapters now available  
from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 14, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794/3 "2006-03-14T19:00:49Z")

</div>

Send is a method from Object that calls the method you specify. That  
code looks weird to me, but I haven’t played with scaffolding in a  
while.

In normal use, you would probably just call the method directly. In this  
case the method is just the field you want to output.

Wes G. wrote:

> All,
> 
> I did a scaffold for a model and I ended up with this code in  
> list.rhtml:
> 
> \<% for column in TargetList.content\_columns %\>
> 
> \<%=h target\_list.send(column.name) %\>  
> \<% end %\>
> 
> Where is the “send” method and what does it do?
> 
> I can’t find it on ActiveRecord::Base? I assume that it returns a  
> value based on the column id but I can’t find any documentation on it.
> 
> Thanks,  
> Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 14, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794/4 "2006-03-14T19:02:35Z")

</div>

Of course, I didn’t go _all_ the way up the inheritance hierarchy :).

I was kind of hoping it was a mixin so I could learn more about them -  
all in due time, I’m sure.

Thanks,  
Wes

Ben Sinclair wrote:

> Send is a method from Object that calls the method you specify. That  
> code looks weird to me, but I haven’t played with scaffolding in a  
> while.
> 
> In normal use, you would probably just call the method directly. In this  
> case the method is just the field you want to output.
> 
> Wes G. wrote:
> 
> > All,
> > 
> > I did a scaffold for a model and I ended up with this code in  
> > list.rhtml:
> > 
> > \<% for column in TargetList.content\_columns %\>
> > 
> > \<%=h target\_list.send(column.name) %\>  
> > \<% end %\>
> > 
> > Where is the “send” method and what does it do?
> > 
> > I can’t find it on ActiveRecord::Base? I assume that it returns a  
> > value based on the column id but I can’t find any documentation on it.
> > 
> > Thanks,  
> > Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 14, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/what-does-the-send-method-do-on-a-model-object/81794/5 "2006-03-14T19:09:46Z")

</div>

Couldn’t you also do something like this ?

\<%=h target\_list.#{column.name} %\>

Untested, but I remember having to call a few methods without knowing  
their  
names first, and used something similar to this… however… send is  
probably more aesthetic than any hack I came up with 🙂
