I need to convert an array of strings and integers into a conjoined string, while preserving the single quotes around the string values. For example, I need to turn this:
["abc", "xyz", 123, 456]
into this:
"'abc','xyz',123,456"
I tried variations on join and to_s, but that’s not quite doing the trick. Any help is appreciated.
I got it working with a one-liner:
["abc", "xyz", 123, 456].to_s.gsub(/[\[\]\"]/,'[' =>'','"'=>'\'')
#=> "'abc', 'xyz', 123, 456"
but I’m still curious if there’s a better way.
When array has strings with numbers to_i converts to integer. If you want to retain it as string. I think you need to use this.