Completely Updated 9/25/2016: Nobody wants rats in their compost. There are a few ways to get them to scram, and a few other ways to keep them from ever getting in, with varying degrees of cost and difficulty.
Let’s start with the easiest and least expensive.
First of all, take care in what you’re composting, and make sure you’re not adding anything rats especially like to your compost. No animal products other than eggshells, no bread, no rice. No eggshells, and many people report that potatoes are a favorite rat food. Used coffee grounds are unlikely to repel rats, but rats don’t want to eat them, and they get the compost cooking quickly.