DMH DMH - 3 months ago 21
Ruby Question

split string without brackets and ensure quotes around each word

I have strings in the following format

as an example. What I need is these to be outputted in the following format
'one', 'word', 'after', 'another'

I have tried
but the output adds brackets which I dont need.

=> ["one", "world", "after", "another"]

I know this is because its an Array.

Can anyone recommend a way to achieve the outcome
'one', 'word', 'after', 'another'


Something like this should work:

puts 'one-world-after-another'.split("-").map {|e| "'#{e}'"}.join(", ")

This produces:

'one', 'world', 'after', 'another'