Ruby array to string conversion
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
> a = ['12','34','35','231']
> a.map { |i| "'" + i.to_s + "'" }.join(",")
=> "'12','34','35','231'"
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(',')