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?
Phlip
(Phlip)
2
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.
It's an instance method of Array:
irb(main):007:0> Array.instance_methods.grep /join/
=> ["join"]