ruby 1.9 how to convert array to string without brackets

后端 未结 4 661
闹比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:25

    Use interpolation instead of concatenation:

    reportStr = "In the first quarter we sold #{myArray[3]} #{myArray[0]}(s)."
    

    It's more idiomatic, more efficient, requires less typing and automatically calls to_s for you.

提交回复
热议问题