I have a ruby array like ['12','34','35','231'].
I want to convert it to a string like '12','34','35','231'.
How can I do that?
I'll join the fun with:
['12','34','35','231'].join(', ')
# => 12, 34, 35, 231
EDIT:
"'#{['12','34','35','231'].join("', '")}'"
# => '12','34','35','231'
Some string interpolation to add the first and last single quote :P
JSON.parse("[12, 39, 100]") will return an array.> a = ['12','34','35','231']
> a.map { |i| "'" + i.to_s + "'" }.join(",")
=> "'12','34','35','231'"
"'#{i}'" instead.try this code ['12','34','35','231']*","
will give you result "12,34,35,231"
I hope this is the result you, let me know
array.map{ |i| %Q('#{i}') }.join(',')
"'#{i}'" instead."string_arr.map(&:inspect).join(',') # or other separator