开发者

Convert a string to an an array-like string to an array in Ruby [duplicate]

This question already has answers here: Closed 11 years ago.

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜