开发者

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

开发者 https://www.devze.com 2023-02-27 03:15 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I convert a Ruby string with brackets to an array?
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

精彩评论

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