How can I 'join' an array adding to the beginning of the resulting string the first character to join?

前端 未结 6 1093
感动是毒
感动是毒 2021-01-21 06:11

I am using Ruby on Rails 3 and I am trying join an array with the & character. I read the Ruby documentation about that.

My array is:

6条回答
  •  自闭症患者
    2021-01-21 06:33

    The whole point of join is that you only get characters between the joined items. You want one in front of every item. I don't know of a short way, but it seems more natural just to map them and then join them without a delimiter:

    ["name1", "name2"].map{|item| '&'+item}.join
    

提交回复
热议问题