Orsay Orsay - 6 months ago 24
Ruby Question

Delete elements from string + transform it into array

I have this string :

data = "[\"super\", \"cool!\", \"bien écrit\", \"first!\", \"why is everyone speaking French here?\"]"


I would like to transform it to be like :
data = ["super", "cool!", "bien écrit", "first!", "why is everyone speaking French here?"]

Answer

Parse it like a JSON. Try

require 'json'
data = JSON.parse data