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:
["name1", "name2"]
If I do
["name1", "name2"].join("&")
it results as
name1&name2
I would like that results as
&name1&name2 # Note the first "&"
A solution is
["", "name1", "name2"].join("&")
but I think it is not a “right way”.
So, how can I have &name1&name2 without using ["", "name1", "name2"].join("&")?
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: