Say I have a string with comma delimited values enclosed in single quotes that may or may not include commas, like this:
"'apples,bananas','lemons'"
and I want to split that into an array
["apples,bananas", "lemons"]
Apparently, if I split(',')
the string I get
[ "'apples", "bananas'", "lemons" ]
which I don't understand. The only way to do this that I've come up with is
a = []
s = "'apples,bananas','lemons'"
s.scan(/\'([^\']+)\'/){|i| a << i[0]}
# result is ["apples,bananas", "lemons"]
But is there a more elegant way? Is there something with the split method that I don't get, which is causing the strange result?