我在Ruby中有这样一条语句:
@mastertest = connection.execute("select code_ver from mastertest")所以现在我想复制这个二维数组,因为如果我执行类似@temp = @mastertest的操作,当我对@mastertest进行任何更改时,它就会对@temp进行更改。
我尝试使用以下代码:
@temp = Marshal.load(Marshal.dump(@mastertest))但这给了我一个错误,即"no marshal_dump is defined for class Mysql2::Result"。因此,我假设@mastertest不是二维数组,而是其他类型。
有人能帮我制作这个数组的副本吗?
发布于 2012-10-20 02:16:05
我设法解决了这个问题,使用了以下方法:
@new_array = Array.new
@mastertest.each { |r| @new_array.push(r[0]) }https://stackoverflow.com/questions/12931025
复制相似问题