All of my best 'tricks' and analogies I use to teach my students aren't the result of stealing or lengthy thinking, but they come to me on the spot.
"It's a hammer-on, think of your finger as a hammer. If you're gonna hammer a nail into the wall, do you go from right in front of the head of the nail, or do you take some distance? Do you come at it head-on, or do you use an arched movement?"
Unfortunately I didn't have a hammer with me for that particular lesson but the student got it, an came back the next week producing perfect-sounding hammer-ons.
And that's because he's a good student, one who practises a lot! To be sure, he wasn't just using hammer-ons in that particular part of the piece, but other things too. Why? Muscle memory.
Muscle memory is one of the three factors in learning, the other two being brain memory and strength. Whenever you struggle with a piece, it tends to be just one of these that needs work. You know if it's brain memory if you need to stop to think about it in a special way to remember it. You know it's strength if you stop halfway and curse your aching wrist or hand. And it's muscle memory if you can only get it right when you're not really thinking about it.
There's good news and there's bad news. The bad news is you need to practise a lot. The good news is that you don't really need to think about what you're doing. You can do it while watching the telly, checking your facebook, reading the news...
If you can do this without making your loved ones want to smash your guitar over your head, then you're on your way to perfecting that tricky pattern.