I want to build a new array starting from a hash with the following format:
HashConst = {[120,240] => 60, [240,480]=> 30} #Constant
I need to build a new array and assign as value to a new constant with the following format:
[ [[120,240] ,1], [[240,480], 1] ]
I tried :
NewArrayConst = HashConst.keys.each{ |res| [res, 1]}
but I get instead
[ [120,240], [240,480] ]
Only solution I found is the following:
tempVar = []
HashConst.keys.each_with_index{ |res,idx| tempVar [idx] = [res, 1]}
NewArrayConst = tempVar
Anyone knows a better solution to this and can explain why I cannot get the output I expect from NewArrayConst = HashConst.keys.each{ |res| [res, 1]}. I'm using 2.2.2-p95
Edit:
As many pointed out Hash var name is wrong and misleading, I have updated that to avoid confusion
Hash. Redefining it is a terrible idea.