我从 rest 客户端发送一个数组,然后像这样接收它:"[1,2,3,4,5]"
I send an array from rest client and received it like this: "[1,2,3,4,5]"
现在我只想将它转换成数组而不使用 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)