join(*args) public

Returns a string created by converting each element of the array to a string, separated by the given separator. If the separator is nil, it uses current $,. If both the separator and $, are nil, it uses an empty string.

[ "a", "b", "c" ].join        #=> "abc"
[ "a", "b", "c" ].join("-")   #=> "a-b-c"

For nested arrays, join is applied recursively:

[ "a", [1, 2, [:x, :y]], "b" ].join("-")   #=> "a-1-2-x-y-b"
Show source
Register or log in to add new notes.
January 4, 2012 - (v1_9_2_180)
0 thanks


I use this in views when I need to join a array of objects from a sql request here is a basic version of what I mean.

Code example

<%={ |blog| blog.comment }.join(“ | ”) %>