Forum: Ruby on Rails myObject.send( from Agile Development book

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Shelby W. (Guest)
on 2005-12-27 06:25
(Received via mailing list)
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 %>
    <td><%=h product.send( %></td>
  <% end %>

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
the "send".

Then, I can't find a method "name" anywhere.  Unlike "human_name", it is
listed as one of the methods of a Column in active record. At least I
find it.

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

Can anyone point me in the right direction?
Francois GORET (Guest)
on 2005-12-27 07:46
(Received via mailing list)
I suggest that you use script/console and irb to find stuff that isn't
in the

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",
"dup", "encode64", "eql?", "equal?", "extend", "freeze", "frozen?",
"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",
"nil?", "null", "number?", "object_id", "primary", "primary=",
"private_methods", "protected_methods", "public_methods",
"remove_subclasses_of", "require", "require_gem",
"require_library_or_gem", "respond_to?", "returning", "send",
"silence_stderr", "silence_warnings", "singleton_methods",
"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
Looks like 'send' method accepts either a symbol like :+ or a string "+"
name the method.

Good luck,

Steven S. (Guest)
on 2005-12-27 08:04
(Received via mailing list)
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.

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

In the case of the depot app, that would be product.
Steven S. (Guest)
on 2005-12-27 19:02
(Received via mailing list)
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.
This topic is locked and can not be replied to.