Use each_with_object instead of inject

Replace use of `inject` with `each_with_object` making the code shorter and a easier to read