Hi, in the tutorial "4 Days on Rails" the following code fragment is used: ,---- | <% for column in Category.content_columns %> | <td><%=h category.send(column.name) %></td> | <% end %> `---- Apparently, the send() function returns the column value by name, but where does this function comes from? Unfortunately, neither the tutorial nor the API documentation tell it. -- \ / vlad@hashbang.de \/lad http://www.hashbang.de
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_object.html#Object.send On 01/02/06, Vlad Berditchevskiy <vlad@hashbang.de> wrote:> > Hi, > > in the tutorial "4 Days on Rails" the following code fragment is used: > > ,---- > | <% for column in Category.content_columns %> > | <td><%=h category.send(column.name) %></td> > | <% end %> > `---- > > Apparently, the send() function returns the column value by name, but > where does this function comes from? Unfortunately, neither the tutorial > nor the API documentation tell it. > > -- > \ / vlad@hashbang.de > \/lad http://www.hashbang.de > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060201/f1da280f/attachment.html
On Feb 1, 2006, at 9:37 AM, Gael Pourriel wrote:> On 01/02/06, Vlad Berditchevskiy <vlad@hashbang.de> wrote: Hi, > >> in the tutorial "4 Days on Rails" the following code fragment is >> used: >> >> ,---- >> | <% for column in Category.content_columns %> >> | <td><%=h category.send( column.name) %></td> >> | <% end %> >> `---- >> >> Apparently, the send() function returns the column value by name, but >> where does this function comes from? Unfortunately, neither the >> tutorial >> nor the API documentation tell it. > > http://www.ruby-doc.org/docs/ProgrammingRuby/html/ > ref_c_object.html#Object.sendNo need to search the web: $ ri send ------------------------------------------------------------ Object#send obj.send(symbol [, args...]) => obj obj.__send__(symbol [, args...]) => obj ------------------------------------------------------------------------ Invokes the method identified by _symbol_, passing it any arguments specified. You can use +__send__+ if the name +send+ clashes with an existing method in _obj_. class Klass def hello(*args) "Hello " + args.join('' '') end end k = Klass.new k.send :hello, "gentle", "readers" #=> "Hello gentle readers" -- Eric Hodel - drbrain@segment7.net - http://segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com
send and __send__ are methods on the Object class in Ruby. "Invokes the method identified by symbol, passing it any arguments and block." Bob Silva http://www.railtie.net/> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of Vlad Berditchevskiy > Sent: Wednesday, February 01, 2006 9:24 AM > To: rails@lists.rubyonrails.org > Subject: [Rails] Where is the send() function? > > Hi, > > in the tutorial "4 Days on Rails" the following code fragment is used: > > ,---- > | <% for column in Category.content_columns %> > | <td><%=h category.send(column.name) %></td> > | <% end %> > `---- > > Apparently, the send() function returns the column value by name, but > where does this function comes from? Unfortunately, neither the tutorial > nor the API documentation tell it. > > -- > \ / vlad@hashbang.de > \/lad http://www.hashbang.de > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Vlad Berditchevskiy wrote:> Hi, > > in the tutorial "4 Days on Rails" the following code fragment is used: > > ,---- > | <% for column in Category.content_columns %> > | <td><%=h category.send(column.name) %></td> > | <% end %> > `---- > > Apparently, the send() function returns the column value by name, but > where does this function comes from? Unfortunately, neither the tutorial > nor the API documentation tell it. > > -- > \ / vlad@hashbang.de > \/lad http://www.hashbang.deConsider this: -1.send("abs") -- Posted via http://www.ruby-forum.com/.