I used to masturbate in class all the time.  I would just discreetly push a pen against my clit through my pants.  It wasn't enough stimulation to come, but I would get myself all worked up then excuse myself to the bathroom. There I would fuck myself quickly to completion and then come back to class.