我正在创建一个嵌套数组。当我构建一个新行并将其附加到嵌套数组中时,使用方法clear清除该行,然后重新构建另一个新行,它将清除这两个数组中的行。知道为什么吗?
代码片段:
new_rec = Array.new
new_rec << "string1"
new_rec << "string2"
new_rec << "string3"
new_rec << "string4"
new_csv = Array.new
new_csv << new_rec
new_rec.clear
new_csv #=> [[]]发布于 2015-01-20 07:05:37
这是因为您在new_csv中有new_rec,并且您清除了对象new_rec。
https://stackoverflow.com/questions/28034979
复制相似问题