Refactored check_rubygems_cache_dir using group_by