Here is what I do if I think I'm eating something that will make me gassy later. (At least feel gas pains.) I take two of the fake Beano type tablets before taking a bite. (Mine says: For Gas Pain and Prevention.) It helps me avoid the unwanted symptom of gas pains later.
If I do feel gas pains, I take two Gas X tablets. It usually does the trick for me, but it will take a little while to kick in.
Thought I'd throw it out there. It's worth a try - especially if you have to sit in class for a long time after lunch.