Cabinet of Wonders, a great 'blog in general, has an especially good essy up about OCD, ritual, and mindfulness.
For me, ritualistic actions occupy a rather curious space in my life. On a spiritual level, they represent the sort of submission to a higher power that I reject--I try to avoid saying "Thank god!" or "Oh my god, please let the Cubs win" or whatever. Of course, this refusal to do a perfectly normal and completely meaningless action (there's no god to receive my thanks, after all, so there's no danger of submitting to anything) is an irrational, superstition on its own.
On the other hand, upon spilling salt I enjoy casting a pinch over my left shoulder, and will more often than not attempt to make contact with a wooden surface after I've tempted fate by announcing my hopes out loud.
In the essay, McDougal says, "To throw salt over my shoulder or knock on wood, though my forebrain knows it does not affect the universe, still makes me feel a sense of connection to an older magic". I'm not sure that's the whole thing for me, but that's certainly a part of it.