Every 2-3 hours ideally. Take crackers, pretzels, rolls, something like that into classes and nibble. If a lecturer objects, have a word with them after class and let them know that you're only doing it to keep your IBS under control so you can concentrate on their class! And I'd also recommend carrying a flask of fennel tea around with you and sipping on that throughout the day.
And I also agree that if you really need to pass gas, just excuse yourself and go to the toilets - it'll get worse if you hold it in!