ruby 1.9 how to convert array to string without brackets

后端 未结 4 655
闹比i
闹比i 2021-02-13 17:03

My question is about how to convert array elements to string in ruby 1.9 without getting the brackets and quotation marks. I\'ve got an array (DB extract), from which I want to

4条回答
  •  梦谈多话
    2021-02-13 17:45

    You can use the .join method.

    For example:

    my_array = ["Apple", "Pear", "Banana"]
    
    my_array.join(', ') # returns string separating array elements with arg to `join`
    
    => Apple, Pear, Banana
    

提交回复
热议问题