# myObject.send(column.name) from Agile Development book

**URL:** <https://www.ruby-forum.com/t/myobject-send-column-name-from-agile-development-book/54388>\
**Category:** Rails\
**Created:** [December 27, 2005, 5:25am UTC](https://www.ruby-forum.com/t/myobject-send-column-name-from-agile-development-book/54388 "2005-12-27T05:25:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [December 27, 2005, 5:25am UTC](https://www.ruby-forum.com/t/myobject-send-column-name-from-agile-development-book/54388/1 "2005-12-27T05:25:04Z")

</div>

I’m studying the Agile Development with Rails book. In the chapter that  
first sets up the depot application (page 68), there is this bit of code  
from a view:

\<% for product in @products %\>

 \<% for column in Product.content\_columns %\> \<%=h product.send(column.name) %\> \<% end %\> etc...

I am trying to absorb both Ruby and rails as fast as I can. So I am  
searching both the Ruby API and the Rails API for methods that I don’t  
know. When I lookup “send” in the rails API, I don’t find anything.  
When I  
look it up in the Ruby API, it says that the form is obj.send(symbol  
[,args…]). Well, there is no symbol in use here. So I am confused  
about  
the “send”.

Then, I can’t find a method “name” anywhere. Unlike “human\_name”, it is  
not  
listed as one of the methods of a Column in active record. At least I  
can’t  
find it.

I know what this code accomplishes, but I wish I understood it better.

Can anyone point me in the right direction?  
Thanks,  
Shelby

---

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [December 27, 2005, 6:46am UTC](https://www.ruby-forum.com/t/myobject-send-column-name-from-agile-development-book/54388/2 "2005-12-27T06:46:11Z")

</div>

I suggest that you use script/console and irb to find stuff that isn’t  
in the  
docs.

First go to the directory of your rails app, and do the following:

fg@moo:/opt/www/mart$ script/console  
Loading development environment.

> > Product.columns[1].name  
> > =\> “product\_category\_id”
> 
> > Product.columns[2].name  
> > =\> “reference”
> 
> > Product.columns[2].name.class  
> > =\> String
> 
> > Product.columns[2].methods.sort  
> > =\> ["==", “===”, “=~”, “ **id** ”, “ **send** ”, “`”, “b64encode”, “blank?”,  
> > “class”, “clone”, “dclone”, “decode64”, “decode\_b”, “default”,  
> > “display”,  
> > “dup”, “encode64”, “eql?”, “equal?”, “extend”, “freeze”, “frozen?”,  
> > “hash”,  
> > “human\_name”, “id”, “inspect”, “instance\_eval”, “instance\_of?”,  
> > “instance\_variable\_get”, “instance\_variable\_set”, “instance\_variables”,  
> > “is\_a?”, “kind\_of?”, “klass”, “limit”, “load”, “method”, “methods”,  
> > “name”,  
> > “nil?”, “null”, “number?”, “object\_id”, “primary”, “primary=”,  
> > “private\_methods”, “protected\_methods”, “public\_methods”,  
> > “remove\_subclasses\_of”, “require”, “require\_gem”,  
> > “require\_gem\_with\_options”,  
> > “require\_library\_or\_gem”, “respond\_to?”, “returning”, “send”,  
> > “silence\_stderr”, “silence\_warnings”, “singleton\_methods”,  
> > “subclasses\_of”,  
> > “suppress”, “taguri”, “taguri=”, “taint”, “tainted?”, “text?”, “to\_a”,  
> > “to\_s”, “to\_yaml”, “to\_yaml\_properties”, “to\_yaml\_style”, “type”,  
> > “type\_cast”, “type\_cast\_code”, “untaint”]

So there’s a ‘name’ method which gives you the name of the column.

fg@moo:/opt/www/mart$ irb  
irb(main):001:0\> 5.send(:+, 4)  
=\> 9  
irb(main):002:0\> 5.send("+", 4)  
=\> 9

5 is an object, that has a method “+” and accept another object to add  
it.  
Looks like ‘send’ method accepts either a symbol like :+ or a string “+”  
to  
name the method.

Good luck,

Francois

---

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [December 27, 2005, 7:04am UTC](https://www.ruby-forum.com/t/myobject-send-column-name-from-agile-development-book/54388/3 "2005-12-27T07:04:14Z")

</div>

You found the right send method. The first argument to send is the  
name of the method that you’d like to invoke, followed by any  
arguments needed by the method.

[http://www.ruby-doc.org/core/classes/Object.html#M001048](http://www.ruby-doc.org/core/classes/Object.html#M001048)

Regarding name, it is an attribute of Column, as is default, limit, etc.

[http://api.rubyonrails.com/classes/ActiveRecord/ConnectionAdapters/](http://api.rubyonrails.com/classes/ActiveRecord/ConnectionAdapters/)  
Column.html

In the case of the depot app, that would be product.

---

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [December 27, 2005, 6:02pm UTC](https://www.ruby-forum.com/t/myobject-send-column-name-from-agile-development-book/54388/4 "2005-12-27T18:02:59Z")

</div>

Disregard the last sentence below. It was extraneous.

I had started to say "in the case of the depot app the names of the  
methods would be product.title, product.description, etc.
