I am looking for a good way to convert string like:
"[apples, oranges, [strawberries, peas, grapes]]"
into an array which will look like:
array = [apples, oranges, [strawberries, peas, grapes]].
therefore array[0] = ["apples"], array[1] = ["oranges"], and array[2] = ["strawberries", "peas", "grapes"]
So, whenever in my string I have another inner square brackets, the content between brackets will be a subarray of my base array.
or, for an alternative result that might be useful…
Now, these are vulnerable to code injection exploits if you are not in full control of the input, so you could install a JSON gem and do something like this: