In Ruby, we can convert an array into a string using the join method. The join method takes the array and a separator as the arguments. It then separates the elements in the array using the specified separator value.
The to_s function in Ruby returns a string containing the place-value representation of int with radix base (between 2 and 36). If no base is provided in the parameter then it assumes the base to be 10 and returns.
I'll join the fun with:
['12','34','35','231'].join(', ')
EDIT:
"'#{['12','34','35','231'].join("', '")}'"
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(',')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With