Recreating the inject method for Ruby