use each_with_object to simplify the method and avoid an instance
variable as suggested by @iNecas