对于我的第一个问题,我想问你如何在Ruby中执行以下操作。在Ruby中操作哈希和数组
我有以下方面
variables["foo"] = [1,2,3]
variables["bar"] = [4,5,6,7]
variables[...] = ...
更新散列:该散列将具有键的任意数量=>值对。
所以它代表参数及其可能的值。我想现在“生成”一个包含哈希值的数组,其中键=>值对表示变量的每种可能组合。在上述示例的情况下,我将具有12(= 3×4)的阵列散列那样
[ hash1, hash2, ..., hash16]
其中散列我将是
hash1["foo"] = 1
hash1["bar"] = 4
hash2["foo"] = 1
hash2["bar"] = 5
hash3["foo"] = 1
hash3["bar"] = 6
hash4["foo"] = 1
hash4["bar"] = 7
hash5["foo"] = 2
hash5["bar"] = 4
hash6["foo"] = 3
hash6["bar"] = 4
...
hash16["foo"] = 3
hash16["bar"] = 7
我有几个想法,但所有其中有相当复杂的嵌套环...
非常感谢!
不应该hash2 [“foo”] = 2? – corroded 2010-08-16 10:39:34
我想先得到第一个变量的第一个值和第二个值的每个值,然后是第一个变量的第二个值和第二个值的每个值,等等。 – 2010-08-16 12:27:39