Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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中将其转换为整数值数组_Ruby - Fatal编程技术网

如何在Ruby中将其转换为整数值数组

如何在Ruby中将其转换为整数值数组,ruby,Ruby,所需输出为: [["1"], ["10"], ["7"], ["5"], ["1"], ["1"], ["8"], ["2"], ["2"], ["5"], ["10"]] 我试图将其转换为整数的数组 但我无法做到这一点 我尝试过的代码是: [1, 10, 7, 5, 1, 1, 8, 2, 2, 5, 10] 这将有助于: arr=[["1"], ["10"], ["7"], ["5"], ["1"], ["1"], ["8"], ["2"], ["2"], ["5"], ["10"]]

所需输出为:

[["1"], ["10"], ["7"], ["5"], ["1"], ["1"], ["8"], ["2"], ["2"], ["5"], ["10"]]
我试图将其转换为整数的数组 但我无法做到这一点

我尝试过的代码是:

[1, 10, 7, 5, 1, 1, 8, 2, 2, 5, 10]
这将有助于:

arr=[["1"], ["10"], ["7"], ["5"], ["1"], ["1"], ["8"], ["2"], ["2"], ["5"], ["10"]]
arr_intvalues=arr.flatten     #["1", "10", "7", "5", "1", "1", "8", "2", "2", "5", "10"]
这是“教程的前5分钟”的内容。学习Ruby会更好地为您服务。
arr.flatten.map(&:to_i)