How Ritalin and other ADHD meds (other than Strattera, which started out as an antidepressant) are presumed to work:
People with ADHD have underactive frontal lobes (at least on brain scans). This is the part of the brain that acts as kind of a traffic-control center, determining what you pay attention to and how well you can concentrate, stick to one task, and filter out irrelevant information. It also assists in organization, planning, and self-inhibition.
So, when someone with ADHD takes a stimulant that targets the brain, that traffic-control center gets sped up, so that it's more effective at letting the person control what they pay attention to. So, rather than compensating with hyperactivity, the person can control better what they pay attention to, control how they do things, and think about impulses (like "get out of your seat and check out that cool-looking cloud out the window") before obeying them.
Caffeine works in a very similar way, but it has a more systemic effect: Rather than just targeting the brain, it will target your whole body. That's why your heartbeat speeds up a little and you get the jitters if you've had too much caffeine. For me, extended-release stimulant medication feels a lot like coffee, but without the jitters.
I've also had the "zombie" effect, though. It usually happens when you've had too high a dose of stimulant medication; you just kind of sit there because you're now too inhibited and too controlled. Sometimes if you get that effect you have to start out with a toddler-size dose.
Caffeine is a reasonable substitute for stimulant medication in mild cases of ADHD, but unlike Ritalin and similar medications, addiction is probable (and likely inevitable). If you want to use caffeine to treat ADHD, you won't be able to use it continuously--you have to go off it on weekends or some similar schedule to avoid building up a tolerance. But it is still useful for many people who either can't tolerate stimulants or don't want to use them, or for people who are on stimulants and need a kick-start in the morning before their normal stimulant medication starts being effective.