Ruby on Rails:在数组中的元素之间插入逗号的简短手段?

Nul*_*uli 2 ruby ruby-on-rails

users_allowed_to_be_viewed.map {|u| "#{u.id},"}
Run Code Online (Sandbox Code Playgroud)

但是这给了 1,2,3,

什么是一个简短的方法来获得类似的东西 1,2,3

Rom*_*her 5

数组?

来自http://ruby-doc.org/core/classes/Array.html

 array.join(sep=$,) ? str

Returns a string created by converting each element of the array to a string, separated by sep.

       [ "a", "b", "c" ].join        #=> "abc"
       [ "a", "b", "c" ].join("-")   #=> "a-b-c"
Run Code Online (Sandbox Code Playgroud)