在rails中将字符串转换为Array

问题描述:

我从其他客户端发送一个数组,并像这样接收它:"[1,2,3,4,5]"

I send an array from rest client and received it like this: "[1,2,3,4,5]"

现在,我只想将其转换为Array,而无需使用Ruby的eval方法.我们可以为此使用任何Ruby的默认方法吗?

Now I just want to convert it into Array without using Ruby's eval method. Any Ruby's default method that we could use for this?

 "[1,2,3,4,5]" => [1,2,3,4,5]

也许是这样吗?

   s.tr('[]', '').split(',').map(&:to_i)