If it's my own code in a hobby project that I'm still working on (presumably I am, otherwise I wouldn't have come across it), then I'll often refactor it immediately.
At work it's not as easy of course, since there are budgets and plans, and other people who disagree with mygenius ideas.