This is not a universal recipee for anything, rather a few random points.
1) Make sure your background matches the course expectations. If not, work on it before even thinking of taking an advanced class.
2) Read ahead, not behind. Most teachers will tell you what's coming next and if you come to the class knowing half the story already, you can concentrate on the other half and gain double time for absorbing it.
3) Ask questions, ask questions, and ask questions. Don't sit and try to digest everything on your own.
4) Learn each proof to the level that your professor can wake you up at midnight and you'd be ready to present it right away. Keep in mind that there are millions of theorems but only thousands of proofs, hundreds of proof blocks, and dozens of ideas. Unfortunately, no one has figured out how to transfer the ideas directly yet, so you have to extract them from complicated arguments by yourself.
5) Solve problems, solve problems, and solve problems (not the ones that ask you to do something according to the ready scheme, of course, but the ones that ask you to prove something that is not clear from the beginning). You need to learn how to create simple proofs before you can understand the complex ones.