Yet another variation on the theme:
def foo(a)
  a.inject(Hash.new(0)) { |h, (k1, k2, v)| lambda { |k|
h.update(k=>h[k]+v) }[[k1,k2]] }.map { |k, v| k + [v] }
end