Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 使用splat运算符分解数组时发生SystemStackError_Ruby - Fatal编程技术网

Ruby 使用splat运算符分解数组时发生SystemStackError

Ruby 使用splat运算符分解数组时发生SystemStackError,ruby,Ruby,我有一个应用程序,它将大量数据收集到一个数组中,并将其附加到现有数组中。当我使用splat操作符(用于Array.push)时,会收到一条SystemStackError:stack level too deep消息“大”在150k条目的范围内(每个条目包含其他对象) 在Ruby中合并大型数组的首选方法是什么 gathered_info = function_that_returns_a_large_array_of_hashes() dump.push(*gathered_info) 如果要

我有一个应用程序,它将大量数据收集到一个数组中,并将其附加到现有数组中。当我使用splat操作符(用于
Array.push
)时,会收到一条
SystemStackError:stack level too deep
消息“大”在150k条目的范围内(每个条目包含其他对象)

在Ruby中合并大型数组的首选方法是什么

gathered_info = function_that_returns_a_large_array_of_hashes()
dump.push(*gathered_info)

如果要向数组中添加一组内容,则splat需要将这些内容扩展为单个参数,每个参数占用堆栈空间。因为你已经发现的原因,这对于大列表是不好的

您始终可以直接在阵列上使用:

dump.concat(gathered_info)
那就不那么麻烦了

您通常使用splat,因为没有替代方法可以使用数组,但这里的情况并非如此
concat
完全满足您的需要