I''ve seen some example code that uses what appears to be a string object with a join method, for example: (from "rubyisms in rails") <code> def category_links(article) "Posted in " + article.categories.collect { |c| link_to c.name, { :controller=>"articles", :action => "category", :id => c.permalink }, :rel => "tag" }.join(", ") end </code> But I don''t see api docs in rails or ruby for a join method like this (obviously there are other join methods). It _appears_ that this might be a conditional concat (but perhaps not). anyone familiar with this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joe at CodeGear wrote:> (from "rubyisms in rails")Tell such authors not to squander Ruby''s incredibly expressive power by writing run-on statements. They wouldn''t do that in prose (right??;).> <code> > def category_links(article) > "Posted in " + article.categories.collect { |c| > link_to c.name, > { :controller=>"articles", :action => "category", > :id => c.permalink }, > :rel => "tag" > }.join(", ") > end > </code>That is this: article.categories.collect{ blah blah blah }.join('', '') Array#collect returns an Array, and join() makes it into a string. That''s all. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/29/07, Joe at CodeGear <jmcglynn-T8eQWhSUU4BWk0Htik3J/w@public.gmane.org> wrote:> > I''ve seen some example code that uses what appears to be a string > object with a join method, for example: > > (from "rubyisms in rails") > <code> > def category_links(article) > "Posted in " + article.categories.collect { |c| > link_to c.name, > { :controller=>"articles", :action => "category", > :id => c.permalink }, > :rel => "tag" > }.join(", ") > end > </code> > > But I don''t see api docs in rails or ruby for a join method like this > (obviously there are other join methods). > > It _appears_ that this might be a conditional concat (but perhaps > not). > > anyone familiar with this? > > > > >It''s an instance method of Array: irb(main):007:0> Array.instance_methods.grep /join/ => ["join"] -- Zack Chandler http://depixelate.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---