Convert a string to an an array-like string to an array in Ruby [duplicate]
Possible Duplicate:
How do I convert a Ruby string with brackets to an array?
In rub开发者_运维技巧y, how to transform a string to an array when this string looks-like an array declaration? Is there an equivalent of "eval" methods? I would like to avoid the split method is this case.
Eg.
myString = "[['joey','male','joey@email.com],['jenny','female','jenny@email.com']]"
eval
would do it. However I would recommend using something like JSON.parse
if the data is coming from an untrusted source (i.e. the Internet).
精彩评论