I think you could do this on one line with #each_with_object and use h for the accumulator.