This can be very disconcerting for visitors to my house, who see the rat cage, walk over to see them, and suddenly there's the rat, out and on top of its cage, leaning out to sniff them. They usually leap back, maybe gasp, and (once they regain their composure) ask me how I keep them from running all over the house. But given their freedom, I find that my rats almost never leave home.
A rat's primary goals in life are to have (1) food (and water) as close as possible and (2) a comfy place to sit. (My rats often sleep with a piece of rat or monkey chow for a pillow, so that, should they awake hungry, they don't have to move even an inch.) If freedom interferes in even the slightest way with these goals, a rat will choose to stay in its cage. Your rat only wants you to think he/she wants out because you lock him/her up.
It works like this -- their cage, whatever kind of cage it happens to be, is kept on top of a dresser or bookshelf, a good meter or more off the floor. This is usually difficult (but not impossible) for the rat to climb down, and very difficult for the rat to climb back up. So my rats can get out any time they want, but freedom comes at a price -- you have to wait for the people to wake up to get back home. Most of my rats get out exactly once, and never do it again. They seem to decide that it is better to wait for the people to let you out, than to get out yourself and wait for the people to put you back. (We let the rats run free in some part of the house for at least a while every day.)
There are always exceptions to the rule -- I did have one rat, Hastur, who for a short time, would leave his cage about every other night around 3 in the morning, and would climb into bed with us and try to wake us up so that we would play with him. He soon found that all we did when we woke up at 3 in the morning was put him back in his cage and go back to sleep, so after a few weeks he gave up.
I do close them in a cage if I am going to be gone overnight, so that they don't fall out and get trapped away from food and water. (And on the floor with my two cats, who would not hurt the rats but would be more than happy to follow them around and stare at them, which a rat can find pretty unnerving if it happens to be afraid of cats.) But otherwise I leave it open, giving the rats more room to romp around, and making them easier to pay attention to any time you happen to be near the cage. Of course, sometimes they lean out and grab my hair when I'm sitting at the computer typing . . .