A couple of weeks ago, I got an email from a guy in his 20s just discovering the magic of yoga. He faced roadblocks. "I'm really loving it," he wrote, "but there's just one problem. I keep getting boners during class. It's really embarrassing, and it kind of gets in the way. What should I do?"
Good question! First, you should realize that you're not alone. Yoga, as manifested the Western Hemisphere, is often practiced in large groups of people, many of them young, quite fit, and wearing less than a full complement of clothing. Also, they're stretching and moving their bodies in ways that are almost impossible to not consider erotic. Add that to the fact that the clothes they do wear are by design close-fitting. Yoga creates near-ideal conditions for public arousal. It happens to just about everyone, though perhaps not in such an extreme manifestation.
My most basic, practical recommendation to you is, at least until you can get the situation under control, to practice in the back of the class, maybe off in a corner. If your yoga studio is one of those with beams in the middle of the room for no good reason, maybe you can hide behind the beam, because no one wants to practice near the beam. Alternately, you can take up a home practice, where it really doesn't matter whether or not you've got a stiffy.
Regardless, don't stop practicing. Believe it or not, your hard-ons are a test of sorts. Yoga constantly tests. One of the major reasons to practice, possibly even the only real reason, is to achieve a calm, clear and tranquil mind, to cease thought's endless fluctuations. The sexual urge is our most powerful base desire, emerging deep from our lizard brains, clouding our thoughts and emotions like nothing else. Yoga doesn't teach us to deny such things; that would be dishonest. It happens. As recent scandals have shown, even the most "advanced" yogis can become consumed by lust or worse, leading to immense suffering.
Instead, yoga encourages us to observe our raw feelings and desires as they, ahem, arise. Rather than let them control you, try to see them as random manifestations of your silly mind, and let them pass by until they disappear, like stones skipping across the surface of a lake. This can work. For example:
Once, when I was at a weekend-long Buddhist meditation retreat, in the middle of a two-hour group meditation, I got an erection. I was sitting there on a comfy pillow, wearing comfortable shorts and not doing anything in particular, and it just happened. My boner paid an unplanned visit, like a neighbor coming over to borrow something. There wasn't much I could do about it right then. It hardly mattered what other people thought, since if they were doing the vipassana in the proper way, they were just sitting with their eyes slightly downcast anyway and had no idea about my priapic struggle. I literally had to sit with the sensation. So I went back into my meditation semi-trance, observing the boner, acknowledging the boner, and then I focused on some street sounds in the distance. When I returned, the situation had deflated itself.
Yoga cleans our our systems, but it doesn't purge us of our human essence. The goal isn't to become a robot, without feelings. You're not trying to eradicate the thoughts and desires that naturally emerge as the part of a normal day; you have to learn how to deal with them skillfully, and that takes a lot of trial, error, and practice. So the next time you sense a stirring down below during yoga class, acknowledge its existence, and then focus your attention, as best you can, on something else. This, too, shall pass.